UVa 10088 - Trees on My Island (pick定理)
样例:
输入:
12
3 1
6 3
9 2
8 4
9 6
9 9
8 9
6 5
5 8
4 4
3 5
1 3
12
1000 1000
2000 1000
4000 2000
6000 1000
8000 3000
8000 8000
7000 8000
5000 4000
4000 5000
3000 4000
3000 5000
1000 3000
4
0 0
1000000 0
1000000 1000000
0 1000000
4
0 0
100 0
100 100
0 100
输出:
21
25990001
999998000001
9801
分析:Pick定理:一个计算点阵中顶点在格点上的多边形面积公式:S=a+b/2.0-1,其中a表示多边形内部的点数,b表示多边形边界上的点数,s表示多边形的面积。
首先利用叉积求多边形的面积S;
然后求出b,方法是枚举每条边,然后以改边构成一个直角三角形,直角边长度是n,m,斜边上有的整数点的个数是gcd(n,m)-1(不包括两端点)最后b=b+n;
即可
最后a=S+1-b/2.0;
需要注意的地方是:a可能爆int
#include"stdio.h"
#include"string.h"
#include"algorithm"
#include"stdlib.h"
#include"math.h"
#include"map"
#include"queue"
#include"iostream"
#define M 1009
#define inf 0x3f3f3f3f
#define eps 1e-9
using namespace std;
struct node
{
double x,y;
node(){}
node(double x,double y)
{
this->x=x;
this->y=y;
}
node operator-(node a)
{
return node(x-a.x,y-a.y);
}
node operator+(node a)
{
return node(x+a.x,y+a.y);
}
double operator*(node a)
{
return x*a.x+y*a.y;
}
double operator^(node a)
{
return x*a.y-y*a.x;
}
}p[M];
double len(node a)
{
return sqrt(a*a);
}
double dis(node a,node b)
{
return len(b-a);
}
double cross(node a,node b,node c)
{
return (b-a)^(c-a);
}
int gcd(int a,int b)
{
return b==?a:gcd(b,a%b);
}
int point(node a,node b)
{
int m=(int)(fabs(b.x-a.x)+0.5);
int n=(int)(fabs(b.y-a.y)+0.5);
int r=gcd(m,n);
return r-;
}
int main()
{
int n;
while(scanf("%d",&n),n)
{
for(int i=;i<n;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
double sum=;
node O(,);
double num=n;
for(int i=;i<n;i++)
{
num+=point(p[i],p[(i+)%n]);
sum+=cross(O,p[i],p[(i+)%n]);
}
sum=fabs(sum)/2.0;
double ans=sum+-0.5*num;
printf("%.0f\n",ans+0.001);
}
return ;
}
/*
12
3 1
6 3
9 2
8 4
9 6
9 9
8 9
6 5
5 8
4 4
3 5
1 3
12
1000 1000
2000 1000
4000 2000
6000 1000
8000 3000
8000 8000
7000 8000
5000 4000
4000 5000
3000 4000
3000 5000
1000 3000
4
0 0
1000000 0
1000000 1000000
0 1000000
4
0 0
100 0
100 100
0 100
*/
UVa 10088 - Trees on My Island (pick定理)的更多相关文章
- LightOJ 1418 Trees on My Island (Pick定理)
题目链接:LightOJ 1418 Problem Description I have bought an island where I want to plant trees in rows an ...
- UVa 10088 (Pick定理) Trees on My Island
这种1A的感觉真好 #include <cstdio> #include <vector> #include <cmath> using namespace std ...
- HDU 3775 Chain Code ——(Pick定理)
Pick定理运用在整点围城的面积,有以下公式:S围 = S内(线内部的整点个数)+ S线(线上整点的个数)/2 - 1.在这题上,我们可以用叉乘计算S围,题意要求的答案应该是S内+S线.那么我们进行推 ...
- 【POJ】2954 Triangle(pick定理)
http://poj.org/problem?id=2954 表示我交了20+次... 为什么呢?因为多组数据我是这样判断的:da=sum{a[i].x+a[i].y},然后!da就表示没有数据了QA ...
- Area(Pick定理POJ1256)
Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5429 Accepted: 2436 Description ...
- poj 2954 Triangle(Pick定理)
链接:http://poj.org/problem?id=2954 Triangle Time Limit: 1000MS Memory Limit: 65536K Total Submissio ...
- poj 1265 Area (Pick定理+求面积)
链接:http://poj.org/problem?id=1265 Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: ...
- poj1265Area(pick定理)
链接 Pick定理是说,在一个平面直角坐标系内,如果一个多边形的顶点全都在格点上,那么这个图形的面积恰好就等于边界上经过的格点数的一半加上内部所含格点数再减一. pick定理的一些应用 题意不好懂, ...
- pick定理:面积=内部整数点数+边上整数点数/2-1
//pick定理:面积=内部整数点数+边上整数点数/2-1 // POJ 2954 #include <iostream> #include <cstdio> #include ...
随机推荐
- Android Gradle 编译错误Java finished with non-zero exit value 2
出现这个错误主要有两类错误 依赖包重复 方法数超过65K 针对第一种错误,可能是由于build.gradle里写了 compile fileTree(dir: 'libs', include: ['* ...
- Bluetooth HCI介绍
目录 1. HCI功能 2. HCI Packet 1. HCI Command 2. HCI Event 3. HCI Data 3. HCI传输层 HCI, 主机控制接口(Host Control ...
- 关于c语言二维数组与指针的个人理解及处理办法。
相信大家在学习C语言时,对一维数组和指针的理解应该是自信的,但是,我在学习过程中,看到网上一些博文,发现即便是参加工作的一些专业编程人员,突然碰到二维数组和指针的问题时,也可能会遇到难以处理的诡异问题 ...
- 【Android开发学习笔记】【随笔】UI线程
概念 UI线程 是Android中的主线程,涉及到UI方面的一些操作都需要在ui线程中进行操作 在非ui线程中想操作ui,就会报错 android.view.ViewRoot$CalledFromWr ...
- Combine String---hdu5727 &&& Zipper(LCS变形)
题目链接:http://poj.org/problem?id=2192 http://acm.split.hdu.edu.cn/showproblem.php?pid=5707 http://acm. ...
- ExtractTablesFromSQL
public static string[] ExtractTablesFromSQL(string cmdString) { return Regex.Matches(cmdString, @&qu ...
- JMeter学习-009-JMeter 后置处理器实例之 - 正则表达式提取器(二)多参数获取
前文简述了通过后置处理器 - 正则表达式提取器 获取 HTTP请求 响应结果中的特定数据,未看过的亲,敬请参阅 JMeter学习-008-JMeter 后置处理器实例之 - 正则表达式提取器(一). ...
- Selenium2学习-000-Selenium2初识
什么是 Selenium?Selenium 是 ThoughtWorks 专门为 Web 应用程序编写的一个验收测试工具,是一种 Web 测试框架,开拓了验证 Web 应用程序的新方案,使您可在 We ...
- cxf动态调用wsdl的一个冲突以及解决
cxf发布服务,调用服务的博客很多,这里也就简单贴一下代代码. 环境如下:spring+cxf (maven环境) <cxf.version>2.7.11</cxf.version& ...
- LED的压降
看具体什么LED一下是参考1.直插LED压降红:2.0-2.2V黄:1.8-2.0V绿:3.0-3.2V 额定电流约20mA. 2.贴片LED压降红:1.82-1.88V,电流5-8mA绿:1.75- ...