题目链接: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定理)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. UVa 10088 (Pick定理) Trees on My Island

    这种1A的感觉真好 #include <cstdio> #include <vector> #include <cmath> using namespace std ...

  4. HDU 3775 Chain Code ——(Pick定理)

    Pick定理运用在整点围城的面积,有以下公式:S围 = S内(线内部的整点个数)+ S线(线上整点的个数)/2 - 1.在这题上,我们可以用叉乘计算S围,题意要求的答案应该是S内+S线.那么我们进行推 ...

  5. 【POJ】2954 Triangle(pick定理)

    http://poj.org/problem?id=2954 表示我交了20+次... 为什么呢?因为多组数据我是这样判断的:da=sum{a[i].x+a[i].y},然后!da就表示没有数据了QA ...

  6. Area(Pick定理POJ1256)

    Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5429   Accepted: 2436 Description ...

  7. poj 2954 Triangle(Pick定理)

    链接:http://poj.org/problem?id=2954 Triangle Time Limit: 1000MS   Memory Limit: 65536K Total Submissio ...

  8. poj 1265 Area (Pick定理+求面积)

    链接:http://poj.org/problem?id=1265 Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions:  ...

  9. poj1265Area(pick定理)

    链接  Pick定理是说,在一个平面直角坐标系内,如果一个多边形的顶点全都在格点上,那么这个图形的面积恰好就等于边界上经过的格点数的一半加上内部所含格点数再减一. pick定理的一些应用 题意不好懂, ...

随机推荐

  1. BZOJ4123 : [Baltic2015]Hacker

    黑掉的一定是一个长度为$\lfloor\frac{n+1}{2}\rfloor$的区间. 于是枚举初始点,然后查询包含它的区间的最小值. 通过维护前后缀最小值+单调队列$O(n)$解决. #inclu ...

  2. CentOS6.4 安装Nagios 并监控端口

    1.下载所需文件nagios-3.4.3.tar.gz,nagios-plugins-1.4.15.tar.gz,nrpe-2.14.tar.gz,sendEmail-v1.56.tar.gz 下载地 ...

  3. [Unity2D]Box Collider 2D盒子碰撞器

    盒子碰撞器(BoxCollider2D)是Unity2D中常用的碰撞器,所有为碰撞器,顾名思义,就是用于检测物体之间的碰撞情况的,Unity2D里面除了BoxCollider2D碰撞器之外还集成Box ...

  4. requirejs模块化框架用法分享

      我采用的是一个非常流行的库require.js. 一.为什么要用require.js? 最早的时候,所有Javascript代码都写在一个文件里面,只要加载这一个文件就够了.后来,代码越来越多,一 ...

  5. SPIE Example References

    Journal Article[1] Davis, A. R., Bush, C., Harvey, J. C. and Foley, M. F., "Fresnel lenses in r ...

  6. uva729

    /*题目一大堆,其实意思就是长度为n个二进制数,里面有h个1,将这个二进制数进行全排列,然后输出*/ #include"iostream" #include"algori ...

  7. android之发送短信程序

    首先改写activity_main.xml文件 代码如下: <LinearLayout xmlns:android="http://schemas.android.com/apk/re ...

  8. 离线更新SEPM服务器的病毒定义库

    1. 从http://www.symantec.com/security_response/definitions/download/detail.jsp?gid=sep下载JDB文件    2. 将 ...

  9. Yii2 验证码不显示

    siteController 中,要将captcha 列为任意用户可以访问

  10. Xamarin迁移到 Unified API 注意事项

    参考官方文档: Migrating to Unified API for Components #if __UNIFIED__ ... // Mappings Unified CoreGraphic ...