UVa 10088 (Pick定理) Trees on My Island
这种1A的感觉真好
#include <cstdio>
#include <vector>
#include <cmath>
using namespace std;
typedef long long LL; struct Point
{
LL x, y;
Point(LL x=, LL y=):x(x), y(y) {}
}; Point operator - (const Point& A, const Point& B)
{ return Point(A.x-B.x, A.y-B.y); } LL Cross(const Point& A, const Point& B)
{ return A.x*B.y-A.y*B.x; } typedef vector<Point> Polygon; LL Area(const Polygon& p)
{
LL ans = ;
int n = p.size();
for(int i = ; i < n-; i++) ans += Cross(p[i]-p[], p[i+]-p[]);
return abs(ans/);
} LL gcd(LL a, LL b) { return b == ? a : gcd(b, a%b); } LL Boundary(const Polygon& p)
{
LL ans = ;
int n = p.size();
for(int i = ; i < n-; i++)
{
LL a = abs(p[i+].x - p[i].x);
LL b = abs(p[i+].y - p[i].y);
ans += gcd(a, b);
}
ans += abs(gcd(p[n-].x-p[].x, p[n-].y-p[].y));
return ans;
} int main()
{
//freopen("in.txt", "r", stdin);
int n;
while(scanf("%d", &n) == && n)
{
Polygon poly;
Point p;
for(int i = ; i < n; i++)
{
scanf("%lld%lld", &p.x, &p.y);
poly.push_back(p);
}
LL A = Area(poly);
LL b = Boundary(poly);
printf("%lld\n", A - b/ + );
} return ;
}
代码君
假设平面上有一个顶点均为格点的单纯多边形(simple polygon)
其面积为A,边界上的格点数为b,内部格点数为i,则有恒等关系:
A = b/2 + i - 1
链接:
http://episte.math.ntu.edu.tw/articles/sm/sm_25_10_1/page4.html
从问题的抛出,从特殊情况开始猜想,然后修正,最后给出证明。写得很好。
但是没有证明里面提到的“原子三角形”面积为1/2的命题,难道这个是非常显然的吗?=_=||
维基百科:
http://en.wikipedia.org/wiki/Pick%27s_theorem
比较严格的证明,但没有上一篇通俗易懂。
http://www.cut-the-knot.org/ctk/Farey.shtmlFarey%20Series
这个证明没看,但是后面提到了Pick定理在Farey级数中的应用,留坑,以后再看。
UVa 10088 (Pick定理) Trees on My Island的更多相关文章
- UVa 10088 - Trees on My Island (pick定理)
样例: 输入:123 16 39 28 49 69 98 96 55 84 43 51 3121000 10002000 10004000 20006000 10008000 30008000 800 ...
- 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 ...
- 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 ...
随机推荐
- NPOI读取Excel数据应用
NPOI 是 POI 项目的 .NET 版本.使用 NPOI 你就可以在没有安装 Office 或者相应环境的机器上对 WORD/EXCEL 文档进行读写.NPOI是构建在POI 3.x版本之上的,它 ...
- Flv 视频格式(转)
最近要用到flv,整理了一些flv格式的资料,供参考. flv文件主要由两部分组成:header和body. 1.header header部分记录了flv的类型.版本等信息,是flv的开头,一般都差 ...
- Netty4.x中文教程系列(四) 对象传输
Netty4.x中文教程系列(四) 对象传输 我们在使用netty的过程中肯定会遇到传输对象的情况,Netty4通过ObjectEncoder和ObjectDecoder来支持. 首先我们定义一个U ...
- CodeForces 173B Chamber of Secrets 二分图+最短路
题目链接: http://codeforces.com/problemset/problem/173/B 题意: 给你一个n*m的地图,现在有一束激光从左上角往左边射出,每遇到‘#’,你可以选择光线往 ...
- soft particles
http://developer.download.nvidia.com/whitepapers/2007/SDK10/SoftParticles_hi.pdf nvdia ------------- ...
- mysql数据库主外键级联删除脚本RESTRICT --> CASCADE
在项目中,我们一般在数据库设计的时候做主外键关联设计,要么就不做.但是这样不符合规范,呵呵. 建立主外键关系的时候,默认是不能级联删除的.而出现往往在删除主表的数据时报错, 需要先删除从表然后再删除主 ...
- structs spring hibernate 三者之间有什么关系?
现在开发流行MVC模式,structs在C(控制器)中使用:hibernate在M(模型)中被使用:至于 spring ,最大的作用在于,structs.hibernate的对象,由于在各个层之间相互 ...
- POJ 1862
#include <iostream> #include <algorithm> #include <iomanip> #include <cmath> ...
- C# Log4Net配置
Log4Net是用来记录日志的,可以将程序运行过程中的信息输出到一些地方(文件.数据库.EventLog等),日志就是程序的黑匣子,可以通过日志查看系统的运行过程,从而发现系统的问题.日志的作用:将运 ...
- hdu 1905 小数化分数2
;}