http://poj.org/problem?id=1265
求凸多边形上,凸多边形内的整点个数 以及凸多边形的面积...
pick 定理 : S = L/2 + N -1
S为多边形的面积 , L为多边形上整点的个数 , N为多边形内整点的个数
多边形上点的个数 对两个端点的横纵左边的绝对值做GCD就可以求得
多边形面积对相邻两点用叉积/2 后相加就可求得
/********************* Template ************************/ #include <set> #include <map> #include <list> #include <cmath> #include <ctime> #include <deque> #include <queue> #include <stack> #include <bitset> #include <cstdio> #include <string> #include <vector> #include <cassert> #include <cstdlib> #include <cstring> #include <sstream> #include <fstream> #include <numeric> #include <iomanip> #include <iostream> #include <algorithm> #include <functional> using namespace std; #define EPS 1e-8 #define MAXN (int)1e5+5 #define MOD (int)1e9+7 #define PI acos(-1.0) #define LINF ((1LL)<<50) #define INF (1<<30); #define max(a,b) ((a) > (b) ? (a) : (b)) #define min(a,b) ((a) < (b) ? (a) : (b)) #define max3(a,b,c) (max(max(a,b),c)) #define min3(a,b,c) (min(min(a,b),c)) #define BUG cout<<"BUG! "<<endl #define LINE cout<<"--------------"<<endl #define L(t) (t << 1) #define R(t) (t << 1 | 1) #define Mid(a,b) ((a + b) >> 1) #define lowbit(a) (a & -a) #define FIN freopen("in.txt","r",stdin) #define FOUT freopen("out.txt","w",stdout) #pragma comment (linker,"/STACK:102400000,102400000") // typedef long long LL; // typedef unsigned long long ULL; // typedef __int64 LL; // typedef unisigned __int64 ULL; int gcd(int a,int b){ return b?gcd(b,a%b):a; } int lcm(int a,int b){ return a*b/gcd(a,b); } /********************* F ************************/ struct POINT{ double x,y; POINT(double _x = 0, double _y = 0):x(_x),y(_y){}; }; double multiply(POINT sp,POINT ep,POINT op){ return (sp.x-op.x) * (ep.y-op.y) - (ep.x-op.x) * (sp.y-op.y); } POINT p[MAXN]; int POINT_OnSeg(POINT a,POINT b){ return gcd((int)fabs(a.x-b.x),(int)fabs(a.y-b.y)); } int main() { //FIN; //FOUT; int T; cin>>T; for(int t = 1 ; t <= T ; t++){ int n; cin>>n; cin>>p[0].x>>p[0].y; for(int i = 1 ; i < n ; i++){ double xx, yy; cin>>xx>>yy; p[i].x = p[i-1].x + xx; p[i].y = p[i-1].y + yy; } p[n] = p[0]; double area = 0; for(int i = 0 ; i < n ; i++) area += multiply(POINT(0,0),p[i],p[i+1])/2; int onside = 0; for(int i = 0 ; i < n ; i++) onside += POINT_OnSeg(p[i],p[i+1]); int inside = area + 1 - onside / 2; printf("Scenario #%d: ",t); printf("%d %d %.1lf ",inside,onside,area); } return 0; }