昨天吉老师讲了皮克定理

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

如果用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. informix服务端卸载后重新安装不成功

    可能原因: 1.实例未删除 2.配置文件未删除 安装成功后远程客户端连接不上问题: 1..如果自己设置的数据库实例报错,换一个数据库实例(database)试试,例如sysadmin

  2. 两个div并列居中显示——当display:inline-block;时,两个div无法对齐即一高一矮

    解决办法: 给div添加样式vertical-align: top;

  3. 2017.10.7 QBXT 模拟赛

    题目链接 T1 容斥原理,根据奇偶性进行加减 #include<iostream> #include<cstdio> using namespace std; typedef ...

  4. NGUI类之间的关系架构

    NGUI Drawcall 1.使用同一个altals的元素尽量放在同一个UIPanel下面,在NGUI中,它消耗的drawcall是以每个Panel为独立计算单位进行计算的. 2.如果一个UIPan ...

  5. Servlet中的属性(attribute)和参数(parameter)的区别

    1.引子 初学者对属性(attribute)和参数(parameter)容易搞混.没搞清他们的区别,项目中就可能出现一此莫名其妙的问题. 2.两者的区别 1) 属性(attribute) 属性是在后台 ...

  6. 交叉熵cross entropy和相对熵(kl散度)

    交叉熵可在神经网络(机器学习)中作为损失函数,p表示真实标记的分布,q则为训练后的模型的预测标记分布,交叉熵损失函数可以衡量真实分布p与当前训练得到的概率分布q有多么大的差异. 相对熵(relativ ...

  7. JDK安装及环境变量配置详解

    一.下载(Jdk 1.8 ) 1.下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151 ...

  8. Clang提供的办法

    1.方法弃用警告 #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarati ...

  9. Robot Framework user guide

    http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html

  10. linux文件属性软硬链接知识

    链接的概念 在linux系统中,链接可分为两种:一种为硬链接,另一种为软链接或符号链接.在默认不带参数的情况下,执行ln命令创建的链接是硬链接. 如果使用ln  -s创建链接则为软链接,前面文件类型为 ...