poj 1265 计算几何
题意:多边形的顶点坐标为整数,问多边形内部的整点数,边上的整点数,面积。
分析:向量(0,0)->(x,y)上的整点数为gcd(x, y),
pick定理:面积 = 内部整点数 + 边上整点数/2 - 1.
const int M = 105; int m, in, on; double s; int x[M], y[M]; int gcd(int i, int j){ int t; for( ; i; t=i, i=j%i, j=t){} return abs(j); } double S(int x1, int y1, int x2, int y2){ return (x1*y2 - x2*y1)/2.0; } int main(){ #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); #endif int T; scanf("%d", &T); FOE(t, 1, T){ in = on = 0; s = 0.0; scanf("%d", &m); FOE(i, 1, m) { scanf("%d%d", &x[i], &y[i]); on += gcd(x[i], y[i]); x[i] += x[i-1]; y[i] += y[i-1]; if(i>1 && i<m) s += S(x[i], y[i], x[i-1], y[i-1]); } if(s<0) s = -s; in = s+1-on/2; cout<<"Scenario #"<<t<<":"<<endl; cout<<in<<' '<<on<<' '<<fixed<<setprecision(1)<<s<<endl<<endl; } return 0; }