POJ 1265 Area (computational geometry) (pick theorem)

Source: Internet
Author: User
Tags abs gcd min printf

area:http://poj.org/problem?id=1265

To give you a point of the horizontal ordinate change value, ask how many points in the polygon, how many points in the polygon, and the area of the polygon.

Idea: Pick theorem.

A polygon area formula for calculating vertices at lattice points in a lattice: s=a+b÷2-1, where a represents the number of points within the Polygon, B represents the number of points on the polygon boundary, and S represents the area of the polygon.

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

#include <map> #include <stack> #include <queue> #include <math.h> #include <stdio.h> #inc Lude <stdlib.h> #include <string.h> #include <iostream> #include <limits.h> #include < Algorithm> #define LL long #define MAX (A,B) ((a) > (b)? ( A):(b) #define MIN (a,b) ((a) < (b)? ( A):(B) #define MAX3 (A, B, c) (A>b?max (A, C): Max (b, c)) #define MIN3 (A, B, c) (A<b?min (A, c): Min (b, c)) #define Max4 (A, B, C, D) Max (Max (A, B), Max (C, D)) #define MIN4 (A, B, C, D) min (min (A, b), Min (c, D)) #define EPS 1e-9 #define INF 1 &
  
lt;< using namespace std;
int T, n;
  
int cnt, Ans, A, B; struct point {int x, y;}
  
N[105];
  
int area (Point A, point B) {return a.x*b.y-a.y*b.x;}
    int gcd (int a, int b) {if (b = = 0) {return A;
    else {return gcd (b, a%b);
    } void Solve () {int T;
    scanf ("%d", &t);
   for (int p = 1; p <= T; ++p) {scanf ("%d", &n);     Ans = CNT = n[0].x = N[0].Y = 0;
            for (int i = 1; I <= n; ++i) {scanf ("%d%d", &a, &b);
            n[i].x = N[i-1].x+a;
            N[i].y = n[i-1].y+b;
            Ans + + area (N[i], n[i-1]);
        CNT + + GCD (ABS (a), ABS (b));
        Ans = abs (ans);
        printf ("Scenario #%d:\n", p);
    printf ("%d%d%.1lf\n\n", (ans-cnt+2)/2, CNT, ans*0.5);
    int main (void) {freopen ("data.in", "R", stdin);
    Freopen ("Data.out", "w", stdout);
  
    Solve ();
return 0; } area

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.