题目链接:pku1265 代码:pick定理的运用 /* pick定理:以整点为顶点的简单多边形(任两边不交叉),它内部整点数为inside, 它的边上(包括顶点)的整点数为edge,则它的面积area=inside+edge/2-1 设各边的始末两点的坐标之差为x,y,那么edge等于各边的 gcd(abs(x),abs(y))之和。 */ //3 <= m < 100, of movements of the robot in the first line //.-100 <= dx, dy <= 100 and (dx, dy) != (0, 0). #include<iostream> #include <cmath> using namespace std; int gcd(int a,int b) { if(b==0)return a; return gcd(b,a%b); } #define max 105 struct point { double x,y; }; typedef point polygon[max]; double polygon_area(polygon p,int n) { double area=0.0; int i; for (i=1; i<=n ;i++) area+=p[i-1].x*p[i%n].y-p[i%n].x*p[i-1].y; return area; } int main() { int t,n; int i,j,k; polygon p; int x,y; double inside,edge,area; cin>>t; for(i=1;i<=t;i++) { inside=0.0;edge=0.0; cin>>n;k=0; p[k].x=0,p[k].y=0; for(j=1;j<=n;j++) { cin>>x>>y; edge+=gcd(abs(x),abs(y)); p[k].x=p[k-1].x+x;p[k].y=p[k-1].y+y; k++; } area=polygon_area(p,n); if(area<0)area=-area; inside=area/2+1-edge/2; if(i>1)cout<<endl; printf("Scenario #%d:/n",i); printf("%d %d %.1lf/n",(int)inside,(int)edge,area/2); } system("pause"); return 0; }