zoukankan      html  css  js  c++  java
  • poj3855Blast the Enemy!(多边形重心)

    链接

     1 #include <iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm>
     5 #include<stdlib.h>
     6 #include<vector>
     7 #include<cmath>
     8 #include<queue>
     9 #include<set>
    10 using namespace std;
    11 #define N 100000
    12 #define LL long long
    13 #define INF 0xfffffff
    14 const double eps = 1e-8;
    15 const double pi = acos(-1.0);
    16 const double inf = ~0u>>2;
    17 struct point
    18 {
    19     double x,y;
    20     point(double x=0,double y = 0):x(x),y(y){}
    21 }p[N];
    22 typedef point pointt;
    23 point operator -(point a,point b)
    24 {
    25     return point(a.x-b.x,a.y-b.y);
    26 }
    27 double cross(point a,point b)
    28 {
    29     return a.x*b.y-a.y*b.x;
    30 }
    31 int main()
    32 {
    33     int i,j,n;
    34     int kk = 0;
    35     while(scanf("%d",&n)&&n)
    36     {
    37         for(i = 0 ;  i< n; i++)
    38         scanf("%lf%lf",&p[i].x,&p[i].y);
    39         p[n] = p[0];
    40         double sx = 0,sy = 0,sum =0 ;
    41         for(i = 1; i < n-1 ;i++)
    42         {
    43             double ts = cross(p[i]-p[0],p[i+1]-p[0])/2;
    44             double x = p[0].x+p[i].x+p[i+1].x;
    45             double y = p[0].y+p[i].y+p[i+1].y;
    46             sum+=ts;
    47             sx+=x*ts;
    48             sy+=y*ts;
    49         }
    50         printf("Stage #%d: %.6f %.6f
    ",++kk,sx/3.0/sum,sy/3.0/sum);
    51     }
    52     return 0;
    53 }
    View Code
  • 相关阅读:
    自动化测试先关
    hadoop集群(第二节机器信息分布表)
    hadoop集群(第一节)
    SpringCloud微服务架构学习笔记
    SpringBoot启动一个项目
    VUE框架介绍
    SpringMVC配置与使用
    Spring学习笔记(二)
    8、XML与JSON
    7、主页面访问权限控制
  • 原文地址:https://www.cnblogs.com/shangyu/p/3914685.html
Copyright © 2011-2022 走看看