poj 1265 Area(Pick定理)
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 5666 | Accepted: 2533 |
Description
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
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
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
【思路】
Pick定理
同上题。
【代码】
#include<cstdio>
using namespace std; struct Pt {
int x,y;
Pt(int x=,int y=) :x(x),y(y){};
};
Pt p[];
typedef Pt vec;
vec operator - (Pt a,Pt b) { return vec(a.x-b.x,a.y-b.y); } int abs(int x) { return x<? -x:x; }
int gcd(int a,int b) { return b==? a:gcd(b,a%b); }
int cross(Pt a,Pt b) { return a.x*b.y-a.y*b.x; }
int calc(Pt a,Pt b) { return gcd(abs(a.x-b.x),abs(a.y-b.y)); } int n;
int main() {
int T,kase=;
scanf("%d",&T);
while(T--) {
scanf("%d",&n);
n++;
p[]=Pt(,);
for(int i=;i<n;i++) {
scanf("%d%d",&p[i].x,&p[i].y);
p[i].x+=p[i-].x , p[i].y+=p[i-].y;
}
int S=,b=;
for(int i=;i<n-;i++) {
S += cross(p[i],p[i+]);
b += calc(p[i],p[i+]);
}
b += calc(p[n-],p[])+calc(p[],p[]);
printf("Scenario #%d:\n%d %d %.1f\n\n",++kase,(S-b+)/,b,0.5*S);
}
return ;
}
poj 1265 Area(Pick定理)的更多相关文章
- poj 1265 Area (Pick定理+求面积)
链接:http://poj.org/problem?id=1265 Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: ...
- POJ 1265 Area (Pick定理 & 多边形面积)
题目链接:POJ 1265 Problem Description Being well known for its highly innovative products, Merck would d ...
- poj 1265 Area(pick定理)
Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4373 Accepted: 1983 Description Bein ...
- [poj 1265]Area[Pick定理][三角剖分]
题意: 给出机器人移动的向量, 计算包围区域的内部整点, 边上整点, 面积. 思路: 面积是用三角剖分, 边上整点与GCD有关, 内部整点套用Pick定理. S = I + E / 2 - 1 I 为 ...
- poj 1265 Area( pick 定理 )
题目:http://poj.org/problem?id=1265 题意:已知机器人行走步数及每一步的坐标 变化量 ,求机器人所走路径围成的多边形的面积.多边形边上和内部的点的数量. 思路:1.以 ...
- Area - POJ 1265(pick定理求格点数+求多边形面积)
题目大意:以原点为起点然后每次增加一个x,y的值,求出来最后在多边形边上的点有多少个,内部的点有多少个,多边形的面积是多少. 分析: 1.以格子点为顶点的线段,覆盖的点的个数为GCD(dx,dy),其 ...
- poj 1265 Area 面积+多边形内点数
Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5861 Accepted: 2612 Description ...
- POJ 1265 Area POJ 2954 Triangle Pick定理
Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5227 Accepted: 2342 Description ...
- POJ 1265 Area (pick定理)
题目大意:已知机器人行走步数及每一步的坐标变化量,求机器人所走路径围成的多边形的面积.多边形边上和内部的点的数量. 思路:叉积求面积,pick定理求点. pick定理:面积=内部点数+边上点数/2-1 ...
随机推荐
- (转)C++设计模式——观察者模式
转自:http://www.jellythink.com/archives/359 前言 之前做了一个性能测试的项目,就是需要对现在的产品进行性能测试,获得测试数据,然后书写测试报告,并提出合理化的改 ...
- Cassandra CqlRow fetch DateType / Int32Type
phpcassa library里有个namespace : use phpcassa\Schema\DataType; 当使用cql query得到cqlrow, int32 & Date ...
- php 文件路径设置 set_include_path(); get_include_path();
<?php set_include_path($string); //设置路径 get_include_path(); // 获取当前的路径 //例如:文件路径为: //D:/phpweb/de ...
- 由json生成php配置文件
$str = '<?php return ' . var_export(json_decode($json, true), true) . ';';file_put_contents('./co ...
- android开发环境重装系统之后的配置
前提: 之前配置好的android开发环境:重装系统:压缩了android目录 配置: 安装java环境 安装; 建立JAVA_HOME变量:JAVAHOME添加到path变量 JAVA_HOME=C ...
- PS字体工具字体显示不出来
显示一个小点:搜索了各种答案,扩大字号(最大72)更改前景色和背景色,最正确的解释就是分辨率太低,我发现分辨率是1,一般的设置成300,1分辨率情况下可以在图层那选择文字图层,然后按ctrl+t,拉大 ...
- 限制sqlserver最大内存后无法连接-EXEC sp_configure max server memory
在sql server 中设置了过小的 "max server memory"最大内存后,sqlserver可启动,但是无法连接. 网络上流行的"sqlserver 内存 ...
- ALV 行列 颜色
1)颜色含义 1:海蓝:2:浅清:3:黄色:4:浅蓝:5:青色:6:红色:7:橙色.(1)首位为主颜色:(2)次位为辅助颜色:(3)末位为0时,表示首位数字表为表格的底色:末位为1时,则表示以1为底色 ...
- Android ListView异步加载数据
1.主Activity public class MainActivity extends Activity { private ListView listView; private ArrayLis ...
- [cocos2d] 显示状态与文字
前言: 对于显示数值与文字一般有三种方式可以使用: CCLabelTTF .CCLabelBMFont .CCLabelAtlas 详细区别可参考:cocos2d 中添加显示文字的三种方式(CCLab ...