HDU 1705 Count the grid & amp; jisuanke 35 triangle Interior Point
Question:
Returns a triangle and calculates the entire point in the triangle;
Pique theorem: S = a/2 + b-1; S is the polygon area; a is the point on the side of the polygon; B is the point in the polygon;
A points on the edge can be obtained by Euclidean theorem gcd (x1-x0, y1-y0;
In addition, the 35 Questions for programming websites are also the same method, but two points are provided. You can change the actual content to the annotated part. click here
Code:
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include using namespace std; # define lowbit (a) a &-a # define Max (a, B) a> B? A: B # define Min (a, B) a> B? B: a # define mem (a, B) memset (a, B, sizeof (a) int dir [4] [2] = {1, 0 }, {-1.0}, {}, {0,-1 }}; const double eps = 1e-6; const double Pi = acos (-); static const int inf = ~ 0U> 2; static const int N = 30010; int scan () {int res = 0, flag = 0; char ch; if (ch = getchar ()) = '-') flag = 1; else if (ch> = '0' & ch <= '9') res = ch-'0 '; while (ch = getchar ()> = '0' & ch <= '9') res = res * 10 + (ch-'0'); return flag? -Res: res;} void out (int a) {if (a <0) {putchar ('-'); a =-a;} if (a> = 10) out (a/10); putchar (a % 10 + '0');} int gcd (int a, int B) {return B = 0? A: gcd (B, a % B);} struct point {int x, y;} p [1000], pp [1000]; int ACO SS (point p1, point p2, point p0) {return abs (p1.x-Snapshot X) * (p2.y-Snapshot y)-(p1.y-Snapshot y) * (p2.x-Snapshot X);} int main () {int a, area, ans; while (cin> p [0]. x> p [0]. y> p [1]. x> p [1]. y> p [2]. x> p [2]. y) {// while (cin> p [1]. x> p [1]. y> p [2]. x) // {// p [0]. x = 0, p [0]. y = 0, p [2]. y = 0; if (! P [0]. x &&! P [0]. y &&! P [1]. x &&! P [1]. y &&! P [2]. x &&! P [2]. y) break; pp [0]. x = abs (p [0]. x-p [1]. x); pp [0]. y = abs (p [0]. y-p [1]. y); pp [1]. x = abs (p [1]. x-p [2]. x); pp [1]. y = abs (p [1]. y-p [2]. y); pp [2]. x = abs (p [0]. x-p [2]. x); pp [2]. y = abs (p [0]. y-p [2]. y); a = gcd (pp [0]. x, pp [0]. y) + gcd (pp [1]. x, pp [1]. y) + gcd (pp [2]. x, pp [2]. y); area = aco ss (p [1], p [2], p [0]); // calculate S ans = (area-a + 2)/2; printf (% d, ans);} return 0 ;}
When you want to give up, think of why you persist until now!