1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
| #include <stdio.h> #include <string.h> #include <algorithm> #include <math.h> using namespace std; #define MAX (100 + 10)
struct Point { double x, y; }; Point pts[MAX];
int nN; const int IN = 1; const int EAGE = 2; const int OUT = 3; const double fPre = 1e-8;
double Det(double fX1, double fY1, double fX2, double fY2) { return fX1 * fY2 - fX2 * fY1; }
double Cross(Point a, Point b, Point c) { return Det(b.x - a.x, b.y - a.y, c.x - a.x, c.y - a.y); }
double GetArea() { double fArea = 0.0; Point ori = {0.0, 0.0};
for (int i = 0; i < nN; ++i) { fArea += Cross(ori, pts[i], pts[(i + 1) % nN]); } return fabs(fArea) * 0.5; }
int gcd(int nX, int nY) { if (nX < 0) { nX = -nX; } if (nY < 0) { nY = -nY; } if (nX < nY) { swap(nX, nY); } while (nY) { int nT = nY; nY = nX % nY; nX = nT; } return nX; }
int main() { int nT; int nI, nE; double fArea;
scanf("%d", &nT); int dx ,dy;
for (int i = 1; i <= nT; ++i) { scanf("%d", &nN); nI = nE = 0; pts[0].x = pts[0].y = 0; for (int j = 1; j <= nN; ++j) { scanf("%d%d", &dx, &dy); pts[j].x = pts[j - 1].x + dx; pts[j].y = pts[j - 1].y + dy; nE += gcd(dx, dy); } fArea = GetArea(); nI = (fArea + 1) - nE / 2; printf("Scenario #%d:\n%d %d %.1f\n\n", i, nI, nE, fArea); }
return 0; }
|