poj2954 Triangle
地址:http://poj.org/problem?id=2954
题目:
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 6006 | Accepted: 2576 |
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 1 0 0 5 0 0 5 0 0 0 0 0 0
Sample Output
0 6
Source
1 #include <cstdio> 2 #include <cmath> 3 #include <algorithm> 4 5 using namespace std; 6 7 #define MP make_pair 8 #define PB push_back 9 typedef long long LL; 10 typedef pair<int,int> PII; 11 const double eps=1e-8; 12 const double pi=acos(-1.0); 13 const int K=1e6+7; 14 const int mod=1e9+7; 15 16 int x[5],y[5]; 17 18 int main(void) 19 { 20 while(1) 21 { 22 int ff=0; 23 for(int i=0;i<3;i++) 24 scanf("%d%d",x+i,y+i),ff+=!y[i]&&!x[i]; 25 if(ff==3)break; 26 int cnt=0,s=(x[1]-x[0])*(y[2]-y[0])-(x[2]-x[0])*(y[1]-y[0]); 27 for(int i=0;i<3;i++) 28 cnt+=__gcd(abs(x[(i+1)%3]-x[i]),abs(y[(i+1)%3]-y[i])); 29 printf("%d\n",(abs(s)+2-cnt)/2); 30 } 31 return 0; 32 }
作者:weeping
出处:www.cnblogs.com/weeping/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。