Poj 1265 Area

Source: Internet
Author: User

Area
Time limit:1000 ms   Memory limit:10000 K
Total submissions:4713   Accepted:2129

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


Calculate the geometric problem, master the polygon area formula, and calculate the path points.

The interior point is obtained by the pique theorem, that is, the interior point = Area + path point/2 + 1;


The AC code is as follows:


#include<iostream>#include<cstring>#include<cmath>#include<cstdio>using namespace std;int n;double dx[105],dy[105],x[105],y[105];int step;int ss(int a,int b){    int r,t;    if(a<b)    {t=a;a=b;b=t;}    while(b)    {        r=a%b;        a=b;        b=r;    }    return a;}void work1(){    int i,j;    for(i=1;i<=n;i++)    {        if(dx[i]==0)            step+=abs((int)dy[i]);        else if(dy[i]==0)            step+=abs((int)dx[i]);        else            step+=abs(ss((int)dx[i],(int)dy[i]));        //cout<<step<<endl<<endl;    }}int main(){    int t;    int i,j,cas=0;    cin>>t;    while(t--)    {        cas++;        cin>>n;        x[0]=0;y[0]=0;step=0;        for(i=1;i<=n;i++)        {            cin>>dx[i]>>dy[i];            x[i]=x[i-1]+dx[i];            y[i]=y[i-1]+dy[i];        }        work1();        double sum=0;        for(i=1;i<n;i++)            sum+=0.5*(x[i]*y[i+1]-x[i+1]*y[i]);        int nd;        nd=int(sum+1)-step/2;        printf("Scenario #%d:\n",cas);        cout<<nd<<" "<<step<<" ";        printf("%.1f\n\n",sum);    }    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.