Area
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 5429   Accepted: 2436

Description

Being well known for its highly innovative products, Merck would 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 suspicious observations to the central security office. The only flaw in the system a competitor抯 agent could 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
walls are used. Figure 1 shows the course of a robot around 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 walls. 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 揹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
except 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 would 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 揝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

2
4
1 0
0 1
-1 0
0 -1
7
5 0
1 3
-2 2
-1 0
0 -3
-3 1
0 -3

Sample Output

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

Source

Northwestern Europe 2001

#include <set>
#include <map>
#include <list>
#include <stack>
#include <cmath>
#include <vector>
#include <queue>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
const double eps = 1e-5;
int n,m;
struct node
{
int x;
int y;
}Point[110]; int GCD(int a,int b)//计算边缘上的点,不计起点(将两个点转化为向量,<strong>a</strong>=n<strong>b,</strong>每个向量都可由从起点起,第一个到达格点的点形成的向量组成,(想想为什么),n就是这个向量的x,y的GCD)
{
return b==0?a:GCD(b,a%b);
} int area(node a,node b)//叉积计算面积
{
return a.x*b.y-a.y*b.x;
}
int main()
{
int T;
int m;
int w=1;
scanf("%d",&T);
while(T--)
{
scanf("%d",&m);
int num=0;
int ant=0;
double ans=0;
for(int i=0;i<m;i++)
{
scanf("%d %d",&Point[i].x,&Point[i].y);
if(i)
{
Point[i].x+=Point[i-1].x;
Point[i].y+=Point[i-1].y;
num+=GCD(abs(Point[i].x-Point[i-1].x),abs(Point[i].y-Point[i-1].y));
ans+=area(Point[i-1],Point[i]);
}
}
num+=GCD(abs(Point[n-1].x-Point[0].x),abs(Point[n-1].y-Point[0].y));
ans+=area(Point[m-1],Point[0]);
if(ans<0)
{
ans=-ans;
}
ant=(int)(ans/2-(double)num/2+1);//pick定理
printf("Scenario #%d:\n",w++);
printf("%d %d %.1f\n\n",ant,num,ans/2);
}
return 0;
}

Area(Pick定理POJ1256)的更多相关文章

  1. poj 1265 Area (Pick定理+求面积)

    链接:http://poj.org/problem?id=1265 Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions:  ...

  2. POJ1265——Area(Pick定理+多边形面积)

    Area DescriptionBeing well known for its highly innovative products, Merck would definitely be a goo ...

  3. poj 1265 Area(pick定理)

    Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4373 Accepted: 1983 Description Bein ...

  4. POJ 1265 Area (Pick定理 & 多边形面积)

    题目链接:POJ 1265 Problem Description Being well known for its highly innovative products, Merck would d ...

  5. [poj 1265]Area[Pick定理][三角剖分]

    题意: 给出机器人移动的向量, 计算包围区域的内部整点, 边上整点, 面积. 思路: 面积是用三角剖分, 边上整点与GCD有关, 内部整点套用Pick定理. S = I + E / 2 - 1 I 为 ...

  6. Area(pick定理)

    http://poj.org/problem?id=1265 题意:起始为(0,0),给出每个点的偏移量,求依次连接这些点形成的多边形边界上格点的个数. 思路:先将各个点的坐标求出存入,由pick定理 ...

  7. poj 1265 Area( pick 定理 )

    题目:http://poj.org/problem?id=1265 题意:已知机器人行走步数及每一步的坐标   变化量 ,求机器人所走路径围成的多边形的面积.多边形边上和内部的点的数量. 思路:1.以 ...

  8. poj 1265 Area(Pick定理)

    Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5666   Accepted: 2533 Description ...

  9. POJ 1265 Area POJ 2954 Triangle Pick定理

    Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5227   Accepted: 2342 Description ...

随机推荐

  1. 通用窗口类 Inventory Pro 2.1.2 Demo1(上)

    插件功能 按照Demo1的实现,使用插件来实现一个装备窗口是很easy的,虽然效果还很原始但是也点到为止了,本篇涉及的功能用加粗标出,具体的功能如下: 1.实现了两个窗口,通过点击键盘I来,打开或者关 ...

  2. PHYLIP linux安装

    PHYLIP的安装: http://download.chinaunix.net/download.php?id=29483&ResourceID=8135下载 gunzip phylip-3 ...

  3. javascript 函数参数之中的undefined(zz)

    开始看到很多js函数里都带一个undefined的参数,很是疑惑,后来查了查,原来是这样.假如我们定义了一个函数function a(){  if(arg1===undefined) alert(&q ...

  4. NSMutableDictionary中元素替换

    NSMutableDictionary *dic = [NSMutableDictionary new]; [dic addEntriesFromDictionary:@{@"key&quo ...

  5. PostgreSQL Replication之第十二章 与Postgres-XC一起工作(7)

    12.7 处理故障转移和删除节点 在本节中,我们将看看故障切换如何处理.我们还将看看如何使用安全可靠的方法添加节点到Postgres-XC设置以及如何从Postgres-XC设置删除节点. 12.7. ...

  6. Dropbox能火,为何它的中国同行不能火?

    http://tech.163.com/15/0510/11/AP8II63H000915BF.html Dropbox能火,为何它的中国同行不能火? 2015-05-10 11:33:55 来源:  ...

  7. 转:python webdriver API 之定位 frame 中的对象

    在 web 应用中经常会出现 frame 嵌套的应用,假设页面上有 A.B 两个 frame,其中 B 在 A 内,那么定位 B 中的内容则需要先到 A,然后再到 B.switch_to_frame  ...

  8. [原创]java WEB学习笔记55:Struts2学习之路---详解struts2 中 Action,如何访问web 资源,解耦方式(使用 ActionContext,实现 XxxAware 接口),耦合方式(通过ServletActionContext,通过实现 ServletRequestAware, ServletContextAware 等接口的方式)

    本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...

  9. webDriver中的alert

    driver.switchTo().alert();这句可以得到alert\confirm\prompt对话框的对象,然后运用其方法对它进行操作.对话框操作的主要方法有:   getText()    ...

  10. ajax常用参数

    url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址.前台跳转到后台 请求参数:前台向后台传数据 回调函数:回调函数就是一个自定义的函数在发生特定的事件的时候调用来处理这个事件 ...