POJ 1265 Area
有一种定理,叫毕克定理。。。。
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 4352 | Accepted: 1977 |
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
Sample Input
Sample Output
Scenario #1:
0 4 1.0
Scenario #2:
12 16 19.0
Source
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath> using namespace std; const int maxn=; int gcd(int a,int b)
{
return b==?a:gcd(b,a%b);
} struct point
{
double x,y;
point() {}
point(double a,double b):x(a),y(b){}
}; double det(point a,point b)
{
return a.x*b.y-a.y*b.x;
} struct polyon
{
int n;
point a[maxn];
polyon() {}
double GetArea()
{
double sum=;
a[n]=a[];
for(int i=;i<n;i++)
{
sum+=det(a[i+],a[i]);
}
return fabs(sum/.);
} int Border_Int_Point_Num()
{
int num=;
a[n]=a[];
for(int i=;i<n;i++)
{
num+=gcd(abs(int(a[i+].x-a[i].x)),abs(int(a[i+].y-a[i].y)));
}
return num;
} int Inside_Int_Point_Num(int x,double area)
{
return int(area)+-x/;
}
}PY; int main()
{
int t,cas=;
scanf("%d",&t);
while(t--)
{
scanf("%d",&PY.n);
int X=,Y=;
for(int i=;i<PY.n;i++)
{
int a,b;
scanf("%d%d",&a,&b);
X+=a; Y+=b;
PY.a[i].x=X; PY.a[i].y=Y;
}
double area=PY.GetArea();
int On=PY.Border_Int_Point_Num();
int In=PY.Inside_Int_Point_Num(On,area);
printf("Scenario #%d:\n",cas++);
printf("%d %d %.1lf\n\n",In,On,area);
}
return ;
}
POJ 1265 Area的更多相关文章
- poj 1265 Area 面积+多边形内点数
Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5861 Accepted: 2612 Description ...
- 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 定理 )
题目:http://poj.org/problem?id=1265 题意:已知机器人行走步数及每一步的坐标 变化量 ,求机器人所走路径围成的多边形的面积.多边形边上和内部的点的数量. 思路:1.以 ...
- poj 1265 Area【计算几何:叉积计算多边形面积+pick定理计算多边形内点数+计算多边形边上点数】
题目:http://poj.org/problem?id=1265 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 ...
- POJ 1265 Area POJ 2954 Triangle Pick定理
Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5227 Accepted: 2342 Description ...
- poj 1265 Area(Pick定理)
Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5666 Accepted: 2533 Description ...
- poj 1265 Area(pick定理)
Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4373 Accepted: 1983 Description Bein ...
- 2018.07.04 POJ 1265 Area(计算几何)
Area Time Limit: 1000MS Memory Limit: 10000K Description Being well known for its highly innovative ...
随机推荐
- [iOS OpenCV的使用,灰度和二值化]
看网上方法很多,但版本都不够新,我看了网上一些知识,总结了下,来个最新版Xcode6.1的. 最近主要想做iOS端的车牌识别,所以开始了解OpenCV.有兴趣的可以跟我交流下哈. 一.Opencv的使 ...
- 解决“HTTP/1.1 405 Method not allowed”问题
Apache.IIS.Nginx等绝大多数web服务器,都不允许静态文件响应POST请求,否则会返回"HTTP/1.1 405 Method not allowed"错误. 即,将 ...
- RNN 入门教程 Part 1 – RNN 简介
转载 - Recurrent Neural Networks Tutorial, Part 1 – Introduction to RNNs Recurrent Neural Networks (RN ...
- 【Alpha阶段】第三次Scrum例会
会议信息 时间:2016.10.19 21:00 时长:0.5h 地点:大运村1号公寓5楼楼道 类型:日常Scrum会议 个人任务报告 姓名 今日已完成Issue 明日计划Issue 今日已做事务 工 ...
- runtime使用小例子 - 给对象O-C属性赋值
这些日子在家里学习runtime,看runtime的一些方法和前辈们的博客,我也尝试着写几个runtime有效的运用 一.给对象属性赋值,例如一个WebEntity类 她有三个属性:NSString. ...
- 在linux下如何将文件夹打包
tar tar命令可以用来压缩打包单文件.多个文件.单个目录.多个目录. 常用格式: 单个文件压缩打包 tar czvf my.tar file1 多个文件压缩打包 tar czvf my.tar f ...
- eclipse配置gradle
1.Grandle官网下载Gradle 2.解压文件,配置到环境变量 3.测试安装成功,$ gradle -v 4.打开eclipse,Help-->Install new software,输 ...
- Docker入门教程(九)10个镜像相关的API
Docker入门教程(九)10个镜像相关的API [编者的话]DockerOne组织翻译了Flux7的Docker入门教程,本文是系列入门教程的第九篇,重点介绍了镜像相关的Docker Remote ...
- TemplateDataField
.aspx <ig:TemplateDataField Key="TemplateField_0"> <Header Text="selected&qu ...
- Java对象的多态性(转型)
多态性在面向对象中主要有两种体现: <1>方法的重载与覆写 <2>对象的多态性 对象的多态性:向上转型:子类对象-->父类对象,向上转型会自动完成 向下转型:父类对象-- ...