UVa 10088-trees on My Island (pick theorem)

Source: Internet
Author: User

Examples:

Input:
12
3 1
6 3
7 |
8 4
9 6
9 9
8 9
6 5
5 8
4 4
3 5
1 3
12
1000 1000
2000 1000
4000 2000
6000 1000
8000 3000
8000 8000
7000 8000
5000 4000
4000 5000
3000 4000
3000 5000
1000 3000
4
0 0
1000000 0
1000000 1000000
0 1000000
4
0 0
100 0
100 100
0 100


Output:

21st

25990001

999998000001

9801

Analysis: Pick theorem: A polygon area formula for calculating vertices on lattice points in a lattice: S=a+b/2.0-1, where a represents the number of points inside the polygon, B represents the number of points on the polygon boundary, and S represents the area of the polygon.

Firstly, the area S of polygon is obtained by cross product.

Then find B, the method is to enumerate each edge, and then to change the edge to form a right triangle, the right angle edge length is n,m, the number of integral points on the hypotenuse is gcd (n,m)-1 (excluding the two ends of the point) finally b=b+n;

Can

Finally a=s+1-b/2.0;

The point to note is: A can explode int

1#include"stdio.h"2#include"string.h"3#include"algorithm"4#include"stdlib.h"5#include"math.h"6#include"Map"7#include"Queue"8#include"iostream"9 #defineM 1009Ten #defineINF 0x3f3f3f3f One #defineEPS 1e-9 A using namespacestd; - structnode - { the     Doublex, y; - node () {} -NodeDoubleXDoubley) -     { +          This->x=x; -          This->y=y; +     } ANodeoperator-(Node A) at     { -         returnNode (x-a.x,y-a.y); -     } -Nodeoperator+(Node A) -     { -         returnNode (x+a.x,y+a.y); in     } -     Double operator*(Node A) to     { +         returnx*a.x+y*a.y; -     } the     Double operator^(Node A) *     { $         returnx*a.y-y*a.x;Panax Notoginseng     } - }p[m]; the DoubleLen (Node A) + { A     returnsqrt (A *a); the } + DoubleDis (node A,node b) - { $     returnLen (b-a); $ } - DoubleCross (node A,node b,node c) - { the     return(b-a) ^ (c-a); - }Wuyi intgcdintAintb) the { -     returnb==0? A:GCD (b,a%b); Wu } - intPoint (node A,node b) About { $     intM= (int) (Fabs (b.x-a.x) +0.5); -     intN= (int) (Fabs (B.Y-A.Y) +0.5); -     intR=gcd (m,n); -     returnR1; A } + intMain () the { -     intN; $      while(SCANF ("%d",&N), N) the     { the          for(intI=0; i<n;i++) thescanf"%LF%LF",&p[i].x,&p[i].y); the         Doublesum=0; -Node O (0,0); in         Doublenum=N; the          for(intI=0; i<n;i++) the         { AboutNum+=point (p[i],p[(i+1)%n]); theSum+=cross (o,p[i],p[(i+1)%n]); the         } theSum=fabs (SUM)/2.0; +         Doubleans=sum+1-0.5*num; -printf"%.0f\n", ans+0.001); the     }Bayi     return 0; the } the /* -  A - 3 1 the 6 3 the 9 2 the 8 4 the 9 6 - 9 9 the 8 9 the 6 5 the 5 894 4 4 the 3 5 the 1 3 the  A98  the About  the - 4000101 6000102 8000103 8000 8000104 7000 8000 the 4000106 4000107 4000108  About109  the the 4111 0 0 the 1000000 0113 1000000 1000000 the 0 1000000 the 4 the 0 0117 0118  the119 0 - */

UVa 10088-trees on My Island (pick theorem)

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.