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 ...
随机推荐
- 【BZOJ】【1430】小猴打架
排列组合 蛮逗的…… 这题题干描述的就一股浓浓的Kruskal的气息……很容易就想到是求一个n个点的完全图的生成树个数,然后由于有序,再乘一个n-1的排列数(n-1条边的全排列)即(n-1)! 但是我 ...
- linux挂载windwos共享文件
mount -t cifs -o useaname=***,password=*** //172.16.82.32/test /mnt username,password分别为windows那边允许共 ...
- centos6.5\win7双系统安装配置
一.安装所需软件 1.分区助手专业版PACNPro.exe(必需):用来对硬盘分区,将磁盘的一部分格式化成Linux可以识别的ext3格式 2.Ext2Fsd(硬盘安装必需,光盘安装不用):因为Win ...
- Firefox下网页缩放时防止div被挤到下一层
http://wu110cheng.blog.163.com/blog/static/13334965420121120102439190/ Firefox下网页缩放时防止div被挤到下一层 问题:三 ...
- [SQL Server 系] T-SQL数据库的创建与修改
创建数据库 USE master; GO CREATE DATABASE ToyUniverse ON ( NAME = ToyUniverse_Data, FILENAME = 'F:\Projec ...
- Android 虚拟机安装SD卡
在cmd命令行下,进入platform-tools目录下. 1.创建sdcard mksdcard -l mycard 256M E:\android\myCards\mysdcard.img ...
- HTTP 408请求超时错误解决办法
错误描述 对于大多数网站而言,我们所看到的错误消息已经是开发者定制过的页面,比如我们最常见的自定义404错误页面,一般而言,我们看到的408错误应该是类似这样的提示:“408:Request Time ...
- hdu1020 Encoding
http://acm.hdu.edu.cn/showproblem.php?pid=1020 过了的就是好孩子........ #include<stdio.h> #include< ...
- XML中如何使用schema
Schema简介 DTD的语法相当复杂,并且它不符合XML文件的标准,自成一个体系,W3C定义的Schema用来代替DTD. chema相对于DTD的明显好处是XML Schema文档本身也是XML文 ...
- 【Linux高频命令专题(20)】du
概述 显示每个文件和目录的磁盘使用空间. 命令格式 du [选项][文件] 文件缺省就代表当前目录大小 参数 -a或-all 显示目录中个别文件的大小. -b或-bytes 显示目录或文件大小时,以b ...