昨天吉老师讲了皮克定理

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

如果用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. 字符串(String)杂谈

    作者:臧圩人(zangweiren) 网址:http://zangweiren.javaeye.com >>>转载请注明出处!<<< 上一次我们已经一起回顾了面试题 ...

  2. 批量格式化json

    单个文件格式化工具: vscode和sublime都有格式化json的插件. 但是笔者遇到的情况是有几百个文件需要格式化,不可能每个文件都打开,进行分别格式化. 于是写了一个python脚本,非常强大 ...

  3. polygon 画图

    cityscape数据集,我现在想根据json文件中的polygon画出整个road的区域,这是运行的脚本.这个文件必须使用coco的pythonAPI的包,把这个脚本放在pythonAPI文件夹下就 ...

  4. momentum公式

    momentum对于w的更新公式: http://caffe.berkeleyvision.org/tutorial/solver.html

  5. python_91_正则表达式

    常用的正则表达式: '.' 默认匹配除\n之外的任意一个字符,若指定flag DOTALL,则匹配任意字符,包括换行 '^' 匹配字符开头,若指定flags MULTILINE,这种也可以匹配上(r& ...

  6. javaweb基础(15)_jsp基础语法

    任何语言都有自己的语法,JAVA中有,JSP虽然是在JAVA上的一种应用,但是依然有其自己扩充的语法,而且在JSP中,所有的JAVA语句都可以使用. 一.JSP模版元素 JSP页面中的HTML内容称之 ...

  7. @private@protected@public@package

    @private@protected@public@package 为了强制一个对象隐藏其数据,编译器限制实例变量范围以限制其在程序中的可见性 但是为了提供灵活性,苹果也让开发者显式设置范围(四选一) ...

  8. JavaScript递归实现对象深拷贝

    let personOne = { name:"张三", age:18, sex:"male", children:{ first:{ name:"z ...

  9. LEETCODE60——第K个排列

    class Solution { public: string getPermutation(int n, int k) { '); vector<bool> flag(n, false) ...

  10. 如何用 CSS 和 D3 创作火焰动画

    效果预览 在线演示 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/xJdVxx 可交互视频 ...