# hihocoder 1083

### 输入

【参数说明】

3 <= N <= 8000

|Xi|, |Yi| <= 20000

### 解题

so，这里：

${\iint }_{D}\left(x+y\right)dxdy={\iint }_{D}xdxdy+{\iint }_{D}ydxdy=\left({x}_{g}+{y}_{g}\right)s$$\iint_{D}(x+y) dxdy=\iint_{D} x dxdy +\iint_{D} y dxdy=(x_g+y_g)s$ ，s自然是这个多边形的面积。

​ ​ ​ ​ ​ ​ ​ ​ $\left({y}_{{p}_{0}}+{y}_{{p}_{1}}+{y}_{{p}_{2}}\right)/3={y}_{g}$$(y_{p_0}+y_{p_1}+y_{p_2})/3=y_g$

### 代码

#include <bits/stdc++.h>
using namespace std;
struct Point{
double x,y;
Point(double x,double y):x(x),y(y){}
Point(){}
};
typedef Point Vector;
Point operator+(Point a,Point b){return Point(a.x+b.x,a.y+b.y);}
Point operator-(Point a,Point b){return Point(a.x-b.x,a.y-b.y);}
Point operator*(Point a,double D){return Point(a.x*D,a.y*D);}
Point operator/(Point a,double D){return Point(a.x/D,a.y/D);}
bool operator < (const Point &a, const Point & b){return a.x < b.x || (a.x == b.x && a.y < b.y);}
const double eps=1e-10;
int dcmp(double x){if(fabs(x)<eps) return 0; else return x<0?-1:1;}
bool operator==(const Point& a,const Point& b){return dcmp(a.x-b.x)==0&&dcmp(a.y-b.y)==0;}
/*
dot        向量间的点积
length     向量的模
angle      向量间的夹角弧度
cross      向量间的叉积
area2      三点围成三角形有向面积的两倍
rotate     向量绕起点逆时针旋转一定弧度后的向量
normal     求向量的单位法线
*/
double dot(Vector a,Vector b){return a.x*b.x+a.y*b.y;}
double length(Vector a){return sqrt(dot(a,a));}
double angle(Vector a,Vector b){return acos( dot(a,b)/length(a)/length(b) );}
double angle(Vector a){return atan2(a.y,a.x);}
double cross(Vector a,Vector b){return a.x*b.y-a.y*b.x;}
double area2(Point A,Point B,Point C){return cross(B-A,C-A);}
Vector rotate(Vector a,double rad){
}
Vector normal(Vector a){double l=length(a);return Vector(-a.y/l,a.x/l);}
return deg/180 * M_PI;
}
int convexHull(Point *p,int n,Point* ch) {
sort(p,p+n);
int m=0;
for(int i=0;i<n;i++){
while(m>1&&dcmp(cross(ch[m-1]-ch[m-2],p[i]-ch[m-2] ))<=0 )m--;
ch[m++]=p[i];
}
int k=m;
for(int i=n-2;i>=0;i--) {
while(m>k&&dcmp(cross(ch[m-1]-ch[m-2],p[i]-ch[m-2]))<=0)m--;
ch[m++]=p[i];
}
if(n>1)m--;
return m;
}
const int maxn = 8000+10;
Point po[maxn];

double countfun(Point p0,Point p1,Point p2)
{
double s = area2(p0,p1,p2)/2;
double xg = (p1.x + p0.x + p2.x) / 3.0;
double yg = (p1.y + p0.y + p2.y) / 3.0;
return (xg+yg)*s;

}
int main()
{
freopen("in.txt","r",stdin);
int T;
scanf("%d",&T);
while(T--) {
int x,y,n;
scanf("%d",&n);
for(int _=0;_<n;_++ )
scanf("%lf%lf",&po[_].x,&po[_].y);
double ans = 0;
double s = 0;
for(int i=1;i<n-1;i++) {
ans+=countfun(po[0],po[i],po[i+1]);
s+=area2(po[0],po[i],po[i+1])/2;
}
if(s<0) ans=-ans;
cout << fixed << setprecision(2) << ans << endl;
}
return 0;
}



• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120