昨天吉老师讲了皮克定理

皮克定理用于计算点阵中顶点在格点上的多边形面积。对于一个顶点全部在格点上的多边形来说,它的面积计算有如下特点:

如果用a表示位于多边形内部的格点数,b表示位于多边形边界上的格点数,则多边形面积可表示为S = a + b/2 – 1 .

皮克定理用于计算点阵中顶点在格点上的多边形面积。对于一个顶点全部在格点上的多边形来说,它的面积计算有如下特点:

如果用a表示位于多边形内部的格点数,b表示位于多边形边界上的格点数,则多边形面积可表示为S = a + b/2 – 1 .

A lattice point is an ordered pair (x, y) where x and y are both integers. Given the coordinates of the vertices of a triangle (which happen to be lattice points), you are to count the number of lattice points which lie completely inside of the triangle (points on the edges or vertices of the triangle do not count).

InputThe input test file will contain multiple test cases. Each input test case consists of six integers x1, y1, x2, y2, x3, and y3, where (x1, y1), (x2, y2), and (x3, y3) are the coordinates of vertices of the triangle. All triangles in the input will be non-degenerate (will have positive area), and -15000 ≤ x1, y1, x2, y2, x3, y3 ≤ 15000. The end-of-file is marked by a test case with x1 = y1 = x2 = y2 = x3 = y3 = 0 and should not be processed.

OutputFor each input case, the program should print the number of internal lattice points on a single line.Sample Input

0 0 1 0 0 1
0 0 5 0 0 5
0 0 0 0 0 0

Sample Output

0
6

所以直接叉积算面积,点的话可以gcd,so easy

#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second
pair<int,int>P[],M[];
int main()
{
while(cin>>P[].x>>P[].y>>P[].x>>P[].y>>P[].x>>P[].y)
{
if(!P[].x&&!P[].y&&!P[].x&&!P[].y&&!P[].x&&!P[].y)break;
int sum=abs((P[].x-P[].x)*(P[].y-P[].y)-(P[].y-P[].y)*(P[].x-P[].x));
for(int i=;i<;i++)
M[i].x=abs(P[i].x-P[i-<?i+:i-].x),M[i].y=abs(P[i].y-P[i-<?i+:i-].y),sum-=__gcd(M[i].x,M[i].y);
cout<<sum/+<<"\n";
}
}

友情放送多边形重心(也可以求面积,取abs就好了),这篇博客的C

HDU - 1705 Count the grid的更多相关文章

  1. HDU 3336 Count the string(KMP的Next数组应用+DP)

    Count the string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  2. hdu 4255 A Famous Grid

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4255 A Famous Grid Description Mr. B has recently dis ...

  3. HDU 5901 Count primes 论文题

    Count primes 题目连接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5901 Description Easy question! C ...

  4. hdu 3336 Count the string -KMP&dp

    It is well known that AekdyCoin is good at string problems as well as number theory problems. When g ...

  5. HDU 6470 Count 【矩阵快速幂】(广东工业大学第十四届程序设计竞赛 )

    题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6470 Count Time Limit: 6000/3000 MS (Java/Others)    ...

  6. 【hdu1705】Count the grid(皮克定理)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=1705 [题意] 给出平面上三个点坐标,求围成的三角形内部的点数 做这道题需要先了解下皮克定理. 百度百科: ...

  7. HDU 4372 Count the Buildings

    Count the Buildings Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  8. hdu 6016 Count the Sheep(思维)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6016 题意:给定男羊和女羊的朋友关系,即给定一个图,问从任意一只羊开始连续数四只不相同的羊的方法数. ...

  9. hdu 5901 count prime & code vs 3223 素数密度

    hdu5901题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5901 code vs 3223题目链接:http://codevs.cn/problem ...

随机推荐

  1. jenkins只能同时构建2个Job怎么办?

    在jenkins 构建任务时,同时只能构建2个,如果两个没有job没有结束,构建第3个就会不执行: 提示: pending—Waiting for next available executor on ...

  2. 远程桌面连接(mstsc)无法断开的解决方案

    某2008 r2有二个系统账户,同时允许两个tcp连接,但每个用户仅同时允许一人登录.不知何因,关闭远程桌面连接的窗口后,再次连接就瞬间提示无法被连接.查看了事件查看器,信息为被注销,这是因为设置了“ ...

  3. Spoj REPEATS 后缀自动机+set

    REPEATS - Repeats 链接:http://www.spoj.com/problems/REPEATS 题意:求S串中某个子串连续循环次数最多的次数. 想法: 从暴力开始,枚举所有串,求出 ...

  4. 团队作业——项目Alpha版本发布

    ---恢复内容开始--- https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass1   https://edu.cnblogs.com ...

  5. PAT (Basic Level) Practise (中文)- 1018. 锤子剪刀布 (20)

    http://www.patest.cn/contests/pat-b-practise/1018 大家应该都会玩“锤子剪刀布”的游戏:两人同时给出手势,胜负规则如图所示: 现给出两人的交锋记录,请统 ...

  6. Luogu P2073 送花

    权值线段树的模板题 然而AC后才发现,可以用\(\tt{set}\)水过-- 权值线段树类似于用线段树来实现平衡树的一些操作,代码实现还是比较方便的 #include<iostream> ...

  7. C/C++基础知识:函数指针和指针函数的基本概念

    [函数指针] 在程序运行中,函数代码是程序的算法指令部分,它们和数组一样也占用存储空间,都有相应的地址.可以使用指针变量指向数组的首地址,也可以使用指针变量指向函数代码的首地址,指向函数代码首地址的指 ...

  8. SpringMVC 项目中引用其他 Module 中的方法

    1. 将要引用的Module 引入项目中 2. 在主Module中添加依赖, 3. 被引用的类必须放在 Module 中/src/下的某个package中,否则引用不到(重要)

  9. 安全和加密——openssl及自建CA

    一.对称加密算法 对称加密:加密和解密使用共用一个秘钥 特点 加密.解密使用同一个秘钥,效率高: 将原始数据分割成固定大小的块,逐个进行加密 缺点 密钥过多,密钥需要分发 数据来源无法确认 1. 使用 ...

  10. 【linux】【磁盘分割】Linux磁盘分割

    全部的磁盘阵列容量均给/cluster/raid目录,占有2TB的容量: 2 GB的swap容量: 分割出/, /usr, /var, /tmp等目录,避免程序错误造成系统的困扰: /home也独立出 ...