POJ2954Triangle【pick公式】
来源:互联网 发布:企业损益表数据 编辑:程序博客网 时间:2024/06/06 20:30
Description
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).
Input
The 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.
Output
For each input case, the program should print the number of internal lattice points on a single line.
Sample Input
0 0 1 0 0 10 0 5 0 0 50 0 0 0 0 0
Sample Output
06
题意:和poj1265一样只不过本题为三角形做poj1265不知道两求两点之间的点数用了枚举加点在线段上的判断之后看了别人的代码发现可以直接求两点的gcd获得除起点外在该线段上的点数所以用到这道题上刚好。
#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>using namespace std;int gcd(int a,int b){return b==0?a:gcd(b,a%b);}int main(){int x1,x2,x3,y1,y2,y3,i,j,k;while(scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3),x1||x2||x3||y1||y2||y3){int a=gcd(abs(x2-x1),abs(y2-y1));int b=gcd(abs(x3-x2),abs(y3-y2));int c=gcd(abs(x3-x1),abs(y3-y1));int s=(x3-x2)*(y1-y2)-(y3-y2)*(x1-x2);printf("%d\n",(abs(s)+2-a-b-c)/2);}return 0;}
- Pick公式 POJ2954Triangle
- POJ2954Triangle【pick公式】
- pick公式
- Pick公式
- Pick公式 POJ1265 && POJ2954
- ACM-pick公式
- POJ 2954(Pick公式)
- POJ 1265 pick公式
- POJ 2954 pick公式
- POJ 1265 pick公式
- pku 1265 Area(pick公式)
- POJ 2954 Triangle pick公式
- POJ 1265 Area Pick公式
- POJ 1265 Area pick公式
- poj 1265 ||poj2954 pick公式 网格
- POJ 1265 Area(面积,pick公式)
- 谈求面积的Pick 公式
- POJ 1265 多边形格点数Pick公式
- 第二周项目:C/C++语言中函数参数传递的三种方式
- 1247 -- 分解整数
- 第一次写博客
- ${pageContext.request.contextPath} JSP取得绝对路径
- LeetCode之Shortest Palindrome
- POJ2954Triangle【pick公式】
- 箴言
- 1248 -- 谁是MR.2
- css选择器详解
- MongoDB错误1_启动mongodb时遇到child process failed,existed with error number 1错误
- Android应用开发EditText文本内容变化监听方法
- 转载BP算法介绍好文
- poj2350 Above Average(模拟)
- hdu 5011(博弈)