POJ 1265-area (Computational geometry + pique theorem + Polygon area formula)

Source: Internet
Author: User

Title Address: POJ 1265

Test instructions: Given a lattice polygon, find the internal number in, the number of points on the edge, and the area S.

Ideas: The use of a lot of theorems.

1. Pique theorem: s=in+on/2-1, i.e. in= (2*s+2-on)/2.

2. Polygon Area formula: The sum of the cross product of a vector consisting of two adjacent points and the origin is calculated sequentially.

3. Find the number of lattice points on the edge: a segment that is vertex-based, with points that are covered by GCD (Dx,dy), where Dxdy are the points in the horizontal segment and the points that are vertically accounted for. If DX or dy is 0, the number of points covered is dy or dx.

#include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include < iostream> #include <sstream> #include <algorithm> #include <set> #include <queue> #include <stack> #include <map>using namespace std;typedef long long ll;const int inf=0x3f3f3f3f;const double pi= ACOs (        -1.0); const double esp=1e-6;int gcd (int a,int b) {while (b) {int r=b;        B=a%b;    A=r; } return A; int area (int x1,int y1,int x2,int y2) {return x1*y2-x2*y1;}    int main () {int t,n,i;    int dx,dy;    int x1,y1,x2,y2;    int icase=1;    int in,on;    Double S;    scanf ("%d", &t);        while (t--) {scanf ("%d", &n);        x1=y1=x2=y2=0;        in=on=s=0;            while (n--) {scanf ("%d%d", &dx,&dy);            The x2=x1+dx;//has two points consisting of a rectangular point y2=y1+dy;            S+=area (X1,Y1,X2,Y2);            ON+=GCD (ABS (DX), ABS (DY));            x1=x2;        Y1=y2;        } in= (s+2-on)/2; printf ("Scenario #%d:\n", icase++);    printf ("%d%d%.1lf\n\n", in,on,s/2.0); } return 0;}


POJ 1265-area (Computational geometry + pique theorem + Polygon area formula)

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.