Poj 1265 Area

Source: Internet
Author: User
Area
Time limit:1000 ms
Memory limit:10000 K
Total submissions:4717
Accepted:2131

Description

Being well known for its highly innovative products, Merck wocould definitely be a good target for industrial espionage. to protect its brand-new research and development facility the company has installed the latest system of surveillance robots patrolling the area. these robots move along the walls of the facility and report suspicous observations to the Central Security Office. the only flaw in the system a competitor using agent cocould find is the fact that the robots radio their movements unencrypted. not being able to find out more, the agent wants to use that 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 are situated on a rectangular grid and that only straight wballs are used. figure 1 shows the course of a robot around und an example area.

 
Figure 1: Example area.

You are hired to write a program that calculates the area occupied by the new facility from the movements of a robot along its Wils. you can assume that this area is a polygon with corners on a rectangular grid. however, your boss insists that you use a formula he is so proud to have found somewhere. the formula relates the number I of grid points inside the polygon, the number E of grid points on the edges, and the total area A of the polygon. unfortunately, you have lost the sheet on which he had written down that simple formula for you, so your first task is to find the formula yourself.

Input

The first line contains the number of scenarios.
For each scenario, you are given the number M, 3 <= m <100, of movements of the robot in the first line. The following M lines contain pairs limit x Dy? Of integers, separated by a single blank, satisfying.-100 <= DX, Dy <= 100 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 respect to the current position ). you can assume that the curve along which the robot moves is closed and that it does not intersect or even touch itself doesn t for the start and end points. the robot moves anti-clockwise around the building, so the area to be calculated lies to the left of the curve. it is known in advance that the whole polygon wocould fit into a square on the grid with a side length of 100 units.

Output

The output for every scenario begins with a line containing extends cenario # I :? Where I is 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 two 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


Analysis:

Pick theorem: the Polygon Area Formula for Calculating vertices on a lattice: S = a + B limit 2-1, where a indicates the points inside the polygon, B indicates the number of points on the boundary of the polygon, and s indicates the area of the polygon.


Example 2 is shown in the figure.

The number of inner points, number of boundary points, and area must be output.


1). Formula for solving Polygon Area:



2) points on the boundary of a polygon:

The two vertex links form a boundary.

The number of points passing through the (Boundary) in the two vertex links is the maximum common number of the differences between the two vertices in the horizontal and vertical coordinates.

For example, P1 (1, 3) P2 (3, 7) means 2 (3-1) and 4 (7-3.

The Code is as follows:

 

# Include <stdio. h> # include <math. h> struct point {int X, Y;} p [1000], temp; int G1 (INT V1, int V2) // calculate the points on the polygon boundary {While (V2) {int temp; temp = V2; v2 = V1 % V2; V1 = temp;} return V1;} int G2 (point N, point m) // calculate the area of the polygon {return (N. x * m. y-n.y * m. x) ;}int main () {int N, T, K1, K2, area; // K1: points on the polygon boundary. K2: points inside the polygon int I, j; scanf ("% d", & N); for (I = 1; I <= N; I ++) {scanf ("% d", & T ); k1 = 0; k2 = 0; Area = 0; P [0]. X = 0; P [0]. y = 0; // the start point starts from (0, 0) for (j = 1; j <= T; j ++) {scanf ("% d", & temp. x, & temp. y); P [J]. X = P [J-1]. X + temp. x; P [J]. y = P [J-1]. Y + temp. y; k1 + = G1 (ABS (temp. x), ABS (temp. y); area + = G2 (P [J-1], p [J]);} k2 = (INT) (area/2-k1/2 + 1 ); printf ("Scenario # % d: \ n % d %. 1f \ n ", I, K2, K1, (double (area)/2);} return 0 ;}

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.