poj 1265 Area Pick定理
pick定理: 一个计算点阵中顶点在格点上的多边形面积公式:S=a+b÷2-1,其中a表示多边形内部的点数,b表示多边形边界上的点数,s表示多边形的面积
知道这个这题就没有难度了。
#include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <map> #include <set> #include <string> #include <queue> #include <stack> #include <bitset> using namespace std; #define pb(x) push_back(x) #define ll long long #define mk(x, y) make_pair(x, y) #define lson l, m, rt<<1 #define mem(a) memset(a, 0, sizeof(a)) #define rson m+1, r, rt<<1|1 #define mem1(a) memset(a, -1, sizeof(a)) #define mem2(a) memset(a, 0x3f, sizeof(a)) #define rep(i, n, a) for(int i = a; i<n; i++) #define fi first #define se second typedef pair<int, int> pll; const double PI = acos(-1.0); const double eps = 1e-8; const int mod = 1e9+7; const int inf = 1061109567; const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} }; struct point { int x, y; }a[105]; int gcd(int x, int y) { return y?gcd(y, x%y):x; } int main() { int t, n; cin>>t; for(int casee = 1; casee<=t; casee++) { printf("Scenario #%d:\n", casee); cin>>n; int ans1 = 0, ans3 = 0; double ans2 = 0; a[0].x = 0, a[0].y = 0; for(int i = 1; i<=n; i++) { scanf("%d%d", &a[i].x, &a[i].y); ans1 += gcd(abs(a[i].x), abs(a[i].y)); a[i].x+=a[i-1].x, a[i].y+=a[i-1].y; ans2 += a[i-1].x*a[i].y-a[i-1].y*a[i].x; } ans2 = fabs(ans2/2); ans3 = ans2+1-ans1/2; printf("%d %d %.1f\n\n", ans3, ans1, ans2); } return 0; }