poj2954

题目大意:给定三角形的三个顶点,求内部点有多少。。

思路:先叉积求面积,然后用 S=a + b/2 - 1(皮克公式),a为内部点,b为边上点,求出a。。

code:

 1 /*
 2   State:Accepted
 3   Time:2013-04-06 16:40:55
 4 */
 5 #include<iostream>
 6 #include<fstream>
 7 #include<cstring>
 8 #include<cstdlib>
 9 #include<cstdio>
10 #include<string>
11 #include<cmath>
12 #include<algorithm>
13 using namespace std;
14 struct oo{ int  x , y; };
15 oo a, b, c;
16 
17 int work_x(int x2, int y2, int x1, int y1){
18      return   x1*y2 - x2*y1;  
19 }
20 
21 int gcd(int a, int b){
22     if  (a % b == 0) return b;
23     else return gcd(b , a % b);
24 }
25 
26 int work_p(const oo a, const oo b){
27      int dx = a.x - b.x;
28      int dy = a.y - b.y;
29      int d;
30      if (dx == 0) d = abs(dy);
31      else if (dy == 0) d = abs(dx);
32           else d = gcd(abs(dx), abs(dy));
33      return d;
34 }
35 void solve(){
36       int squre = abs(work_x(b.x - a.x, b.y - a.y, c.x - a.x, c.y - a.y));
37       int tm = work_p(a, b) + work_p(b,c) + work_p(a,c);
38       int ans = (squre + 2 - tm) / 2;
39       printf("%d\n",ans);
40 }
41 
42 int main(){
43      freopen("poj2954.in","r",stdin);
44      freopen("poj2954.out","w",stdout); 
45      while (scanf("%d%d%d%d%d%d",&a.x, &a.y, &b.x, &b.y, &c.x, &c.y) != EOF){
46         if (!a.x && !a.y && !b.x && !b.y && !c.x && !c.y) break;
47         solve();    
48      }
49      fclose(stdin); fclose(stdout);
50 }

 

posted on 2013-04-11 23:41  yzcstc  阅读(181)  评论(0编辑  收藏  举报