POJ 1265 Area (pick theorem)

Source: Internet
Author: User

Area
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 5284 Accepted: 2375

Description

Being well known for it highly innovative products, Merck would definitely BES a good target for industrial espionage. To protect it brand-new and development facility the company have installed the latest system of surveillance rob OTS patrolling the area. These robots move along the walls of the facility and report suspicious observations to the Central Security Office. The only flaw in the system a competitor World抯 agent could find was the fact that the robots radio their movements unencrypted. Not being able-to-find out more, the agent wants to use this information to calculate the exact size of the area occupied By the new facility. It is public knowledge that all the corners of the building be situated on a rectangular grid and so only straight wall S is used. Figure 1 shows the course of a robot around an example area.


Figure 1:example Area.

You is hired to write a program this calculates the area occupied by the new facility from the movements of a robot along Its walls. You can assume the a polygon with corners on a rectangular grid. However, your boss insists that's use a formula he's so proud to has found somewhere. The formula relates the number I of the grid points inside the polygon, the number E of the grid points on the edges, and the Tota L area A of the polygon. Unfortunately, you had lost the sheet on which he had written down then simple formula for you, so your first task was to Find the formula yourself.

Input

The first line contains the number of scenarios.
For each scenario, your is given the number m, 3 <= m <, of movements of the robot in the first line. The following m lines contain pairs hipseat x dy?of integers, separated by a single blank, satisfying. -100 <= dx, dy <= 10 0 and (dx, dy)! = (0, 0). Such A pair means that the robot moves on to a grid point DX units to the right and dy units upwards on the grid (with Res Pect to the current position). You can assume that the curve along which the robot moves are closed and that it does not intersect or even touch itself ex Cept for the start and end points. The robot moves anti-clockwise around the building, so the area is calculated lies to the left of the curve. It is known in advance so the whole polygon would fit into a square to the grid with a side length of units.

Output

The output for every scenario begins and a line containing applicant Cenario #i:? Where I am the number of the scenario starting at 1. Then print a single line containing I, E, and a, the area a rounded to one digit after the decimal point. Separate the three numbers by a single blanks. Terminate the output for the scenario with a blank line.

Sample Input

241 00 1-1 00-175 01 3-2 2-1 00-3-3 10-3

Sample Output

Scenario #1:0 4 1.0Scenario #2:12 16 19.0

Source

Northwestern Europe 2001



Test instructions: Give a simple polygon on a plane, find the point on the edge of the polygon, the point within the polygon, the area of the polygon.



#include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> #include < Stdlib.h> #include <math.h>using namespace std; #define ABS (x) ((x) >0? (    x):-(x)///take absolute value int n;struct node{int x; int y;} Q[100100];int gcd (int a,int b) {return B?GCD (b,a%b): A;}    int Get_line ()////The number of grid points on the polygon {int ret = 0;    for (int i=0; i<n; i++) {ret + = GCD (ABS (q[i].x-q[(i+1)%n].x), ABS (q[i].y-q[(i+1)%n].y)); } return ret;}    Double Get_area ()///Polygon mesh Area {DOUBLE ret = 0;    for (int i=0; i<n; i++) {ret + = q[i].x * q[i+1].y-q[i].y*q[i+1].x; } return ABS (ret)/2;}    int main () {int T;    int k = 0;    scanf ("%d", &t);        while (t--) {scanf ("%d", &n);            for (int i=0; i<n; i++) {scanf ("%d%d", &q[i].x,&q[i].y);                if (i!=0) {q[i].x + = q[i-1].x;            Q[i].y + = Q[i-1].y;  }} int b = Get_line (); The number of grid points on the polygon int A;   Double area = Get_area ();  Polygon Mesh Area A = (int) (areas-(double) b/2.0) + 1);        The number of mesh points within the polygon printf ("Scenario #%d:\n", ++k);        printf ("%d%d%0.1lf\n", A,b,area);    printf ("\ n"); } return 0;}



Copyright NOTICE: This article is the original blogger article, if you have special needs, please contact Bo Master qq:793977586.

POJ 1265 Area (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.