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定理的一些应用 题意不好懂, ...
随机推荐
- LA 3415 (二分图+最大独立集)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- edtftpj让Java上传FTP文件支持断点续传
在用Java实现FTP上传文件功能时,特别是上传大文件的时候,可以需要这样的功能:程序在上传的过程中意外终止了,文件传了一大半,想从断掉了地方继续传:或者想做类似迅雷下载类似的功能,文件太大,今天传一 ...
- _jobdu_1384:二维数组中的查找
/************************************************************************/ /* 题目描述: 在一个二维数组中,每一行都按照从 ...
- hdu Proud Merchants
此题是一个背包的题目,刚开始我并没有作任何的排序工作,所以出来的结果总是错的,仔细想想也确实是不对的,因为q[i]会限制dp[i]的值的变化.虽然我知道要按照某个量进行排序,对原数据进行处理,但是实在 ...
- 仿5173游戏交易平台系统SQL注入(可直接脱裤)+Getshell
最近没事登登好几年前玩过的游戏看看,发现有人喊高价收号,这一看就是骗子,这等骗子还想骗我?我就来看看这逗逼是怎么骗人的,结果发现这人给了一个说是 5173平台交易的网站,叫我直接把号的信息填上去然后填 ...
- Html - Footer
通用的Footer代码片段 <style> #footer { padding: 20px; text-align: center; background-color: #666; bor ...
- NP
一个决定性问题C 若是为NPC,则代表它对NP是完备的,这表示: 它是一个NP问题,且 其他属于NP的问题都可归约成它. 满足条件2(无论是否满足条件1)的问题集合被称为NP-hard.一个NP-ha ...
- Using Vertex Texture Displacement for Realistic Water Rendering
http://blog.csdn.net/soilwork/article/details/709869 Using Vertex Texture Displacement for Realistic ...
- TCP/IP简介
TCP/IP协议分层 提到协议分层,我们很容易联想到ISO-OSI的七层协议经典架构,但是TCP/IP协议族的结构则稍有不同.如图所示 TCP/IP协议族按照层次由上到下,层层包装.最上面的就是应用层 ...
- Nginx 配置文件模板
user www www; worker_processes 2; error_log /usr/local/nginx/logs/nginx_error.log crit; pid /usr/loc ...