「POJ2954」Triangle

2014年4月14日3,1560

Description

lattice point is an ordered pair (xy) 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 x1y1x2y2x3, and y3, where (x1y1), (x2y2), and (x3y3) are the coordinates of vertices of the triangle. All triangles in the input will be non-degenerate (will have positive area), and −15000 ≤ x1y1x2y2x3y3 ≤ 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

Sample Output

题解

Pick定理:对给定顶点坐标均是整点的简单多边形,其面积A和内部格点数目i、边上格点数目b满足:A=i+b/2-1。

边上的格点数=|dx|和|dy|的最大公约数

 

 

avatar
  Subscribe  
提醒