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 ...
随机推荐
- 数据结构1 线段树查询一个区间的O(log N) 复杂度的证明
线段树属于二叉树, 其核心特征就是支持区间加法,这样就可以把任意待查询的区间$[L, R]$分解到线段树的节点上去,再把这些节点的信息合并起来从而得到区间$[L,R]$的信息. 下面证明在线段树上查询 ...
- python dict.get()和dict['key']的区别
先看代码: In [1]: a = {'name': 'wang'} In [2]: a.get('age') In [3]: a['age'] --------------------------- ...
- Redis 学习笔记
1 Redis优势 性能极高 – Redis能读的速度是110000次/s,写的速度是81000次/s . 丰富的数据类型 – Redis支持二进制案例的 Strings, Lists, Hashes ...
- CBOW Model Formula Deduction
Paper Reference: word2vec Parameter Learning Explained 1. One-word context Model In our setting, the ...
- jboss jms 实例
最近温习了下EJB和JMS,整理了下思路,和大家分享下P2P和Pub/Sub的demo :JBoss 7 集成了HornetQ,JMS可以在HornetQ中间件运行,有时间在和大家分享关于Horn ...
- Mysql配置项的简单优化
preface 众所周知,Mysql已经成为广泛使用的开源数据库了,so 公司阿里云的数据库为Mysql,在最开始的时候是直接yum安装,配置项都是默认的,没有任何调整,这次有时间就参考各路大神的资料 ...
- Ubuntu修改mysql默认编码的方法
ubuntu使用apt-get安装mysql后,server的默认编码是latin1,下面把server的编码修改成utf8. 编码相关信息: 1 2 3 4 5 6 7 8 9 10 11 12 1 ...
- Win7 配置Apache+PHP+Mysql环境
第一.安装并配置APACHE(安装到D:\phpapache\Apache2.2) 1.安装时默认安装,Network Domain, Server Name 我填写我的计算机名,Administra ...
- _mkdir
[内容摘要]: C语言 在VS2013环境下使用_mkdir返回值是-,而且文件夹不存在,#include stdio.h#include direct.hmain(){)printf("无 ...
- 2015年最全的移动WEB前端UI框架
目前,众多互联网公司APP都嵌入了大量的HTML5,移动端的开发越来越重视,HTML5的运用场景也越来越多了.在移动WEB开发的过程中,使用合适的移动WEB UI框架可以大大提升我们的开发效率.下面P ...