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 ...
随机推荐
- 关于MDK中:RO-data、RW-data、ZI-data
最近在LPC2109上调试ENC28J60,协议栈使用的是UIP,刚开始用的telnet服务,能够正常编译运行.然后换成webserver提示: enc28j60.axf: Error: L6406E ...
- [转载]C#如何在webBrowser1控件通过TagName,Name查找元素(没有ID时)遍历窗体元素
//防止页面多次刷新页面执行 ) { string GetUserName = System.Configuration.ConfigurationSettings.AppSettings[" ...
- [设计模式] 1/2 工程与抽象工程模式 factory & Abstrac Factory
转载 http://blog.csdn.net/wuzhekai1985 软件领域中的设计模式为开发人员提供了一种使用专家设计经验的有效途径.设计模式中运用了面向对象编程语言的重要特性:封装.继承.多 ...
- PE文件结构详解(二)可执行文件头
在PE文件结构详解(一)基本概念里,解释了一些PE文件的一些基本概念,从这篇开始,将详细讲解PE文件中的重要结构. 了解一个文件的格式,最应该首先了解的就是这个文件的文件头的含义,因为几乎所有的文件格 ...
- asp.net mvc4 使用KindEditor文本编辑器
最近做项目要用文本编辑器,编辑器好多种,这里介绍KindEditor在asp.net mvc4中的使用方法. 一.准备工作: 1.下载KindEditor.去官网:http://www.kindsof ...
- web配置详解
1.启动一个WEB项目的时候,WEB容器会去读取它的配置文件web.xml,读取<listener>和<context-param>两个结点. 2.紧急着,容创建一个Servl ...
- 关于prototype以及继承方面的理解
学习笔记(致 渐悟) 写在前面的话 今天看<javascript高级程序设计>的时候,看到有关继承和原型链prototype时遇到些疑问,特回来研究下,同时也感谢JS群网友"渐悟 ...
- 安装numpy/scipy/scikit-learn的方法
安装numpy 和 scipy sudo yum install lapack lapack-devel blas blas-devel sudo yum install numpy.x86_64 ...
- 【hadoop2.6.0】一句话形容mapreduce
网上看到的: We want to count all the books in the library. You count up shelf #1, I count up shelf #2. Th ...
- 2014多校第一场A题 || HDU 4861 Couple doubi
题目链接 题意 : 有K个球,给你一个数P,可以求出K个值,(i=1,2,...,k) : 1^i+2^i+...+(p-1)^i (mod p).然后女朋友先取,再xp取,都希望赢,如果女朋友能赢输 ...