LightOj1418 - Trees on My Island(Pick定理)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1418
题意:给你多边形中的顶点,n个点按顺时针或逆时针方向给出,然后求出多边形内部有多少个整数点;
皮克定理:
在一个多边形中。用I表示多边形内部的点数,E来表示多边形边上的点数,S表示多边形的面积。
满足:S = I + E/2 - 1;
求E,一条边(x1, y1, x2, y2)上的点数(包括两个顶点)= gcd(abs(x1-x2),abs(y1-y2));
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<stdio.h>
#include<queue>
using namespace std;
#define met(a, b) memset(a, b, sizeof(a))
#define mod 1000000007
typedef long long LL;
///////////////////////////////////////////////////////////////////////////////////////////////
/*
HDU2036题意:有一个多边形,含有n个顶点,按逆时针方向依次给出,求对应的多边形的面积;
*/
const int N = ;
struct point
{
LL x, y; point(){}
point(LL x, LL y):x(x), y(y) {} friend LL operator ^(point p, point q)
{
return p.x*q.y - p.y*q.x;
};
}p[N]; LL gcd(LL a, LL b)
{
return b==?a:gcd(b, a%b);
}
int main()
{
int n, T, t = ;
scanf("%d", &T);
while(T--)
{
scanf("%d", &n);
for(int i=; i<=n; i++)
scanf("%lld %lld", &p[i].x, &p[i].y);
p[] = p[n]; LL S = , E = ;
for(int i=; i<=n; i++)
{
S += p[i]^p[i-];
E += gcd(abs(p[i].x-p[i-].x), abs(p[i].y-p[i-].y));
}
LL I = (abs(S)- E)/ + ; printf("Case %d: %lld\n", t++, I);
}
return ;
}
/*
IN:
1
9
1 2
2 1
4 1
4 3
6 2
6 4
4 5
1 5
2 3
OUT:
Case 1: 8
*/
LightOj1418 - 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 - Trees on My Island (pick定理)
样例: 输入:123 16 39 28 49 69 98 96 55 84 43 51 3121000 10002000 10004000 20006000 10008000 30008000 800 ...
- 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定理的一些应用 题意不好懂, ...
随机推荐
- Distributed RPC —— 分布式RPC
This tutorial showed how to do basic stream processing on top of Storm. There's lots more things you ...
- 洛谷 P1147 连续自然数和 Label:等差数列
题目描述 对一个给定的自然数M,求出所有的连续的自然数段,这些连续的自然数段中的全部数之和为M. 例子:1998+1999+2000+2001+2002 = 10000,所以从1998到2002的一个 ...
- Java之美[从菜鸟到高手演变]之HashMap、HashTable(转载)
http://blog.csdn.net/zhangerqing/article/details/8193118
- ASP.NET中Url重写后,打不开真正的Html页面
不对IIS配置.html的映射,IIS站点目录下.html页面都能显示.当配置了.html的映射 IIS站点目录下真实存在的.html页面无法显示,错误信息:“页面无法显示”解决方法:1.首先照旧在网 ...
- 命令行安装KVM
查看libvirtd的状态: [root@super67 ~]# /etc/init.d/libvirtd status libvirtd (pid 2503) is running... 安装vn ...
- JS让input按钮不能点击
<input value="开通" type="button" id="tijiao" class="button" ...
- 微博java SDK介绍及使用说明
转自:作者:新浪微博 开放平台 @MUNTO_AKIRA http://open.weibo.com/blog/%E5%BE%AE%E5%8D%9Ajava-sdk%E4%BB%8B%E7%BB%8D ...
- Robocopy
用法: http://technet.microsoft.com/zh-cn/library/cc733145%28v=ws.10%29.aspx 图形化工具: http://sourceforg ...
- 【iCore3 双核心板】例程二十八:FSMC实验——读写FPGA
实验指导书及代码包下载: http://pan.baidu.com/s/1gerjjxh iCore3 购买链接: https://item.taobao.com/item.htm?id=524229 ...
- ubuntu + subversion + apache2 设置
1.下载安装subversion,apache2 sudo apt-get updatesudo apt-get upgrade sudo apt-get install apache2sudo a ...