• 多边形重心,面积


    多边形面积

    改革春风吹满地

    #include<bits/stdc++.h>
    using namespace std;
    struct point
    {
       double x,y;
    }node[10001];
    double cosr(point a,point b,point c)
    {
       return (a.x-c.x)*(b.y-c.y)-(a.y-c.y)*(b.x-c.x);
    }
    int main( )
    {
       int n;
       while(cin>>n&&n)
       {
           double sum=0;
           for(int i=0;i<n;i++)
           {
              cin>>node[i].x>>node[i].y;
           }
           for(int i=1;i<n-1;i++)
           {
              sum+=cosr(node[i],node[i+1],node[0]);
           }
           printf("%.1lf
    ",sum/2.0);
       }
       return 0;
    }
    

    多边形重心

    #include<bits/stdc++.h>
    using namespace std;
    struct tree
    {
       double x,y;
    } node[1000010];
    double sum(tree a,tree b,tree c)
    {
       return (a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y);
    }
    int main( )
    {
       int t,n;
       cin>>t;
       while(t--)
       {
           cin>>n;
           double res=0;
           double ans=0;
           tree p;
           p.x=0;
           p.y=0;
           for(int i=0; i<n; i++)
           {
               cin>>node[i].x>>node[i].y;
           }
           for(int i=1; i<n-1; i++)
           {
               ans=sum(node[i],node[i+1],node[0]);
               res+=ans;
               p.x+=ans*(node[i].x+node[i+1].x+node[0].x)*1.0/3;
               p.y+=ans*(node[i].y+node[i+1].y+node[0].y)*1.0/3;
           }
           p.x/=res*1.0;
           p.y/=res*1.0;
           printf("%.2lf %.2lf
    ",p.x,p.y);
       }
    
       return 0;
    }
    
  • 相关阅读:
    uva 10129 poj 1386 hdu 1116 zoj 2016 play on words
    redis持久化
    Redis事务
    非阻塞I/O多路复用机制
    SFTP
    FTP
    http协议特点及session共享及单点登录
    什么是cookie以及cookie的特性、优缺点
    异步IO和同步IO的区别:
    TCP操作与原理
  • 原文地址:https://www.cnblogs.com/lcbwwy/p/13125283.html
Copyright © 2020-2023  润新知