pku3668 Game of Lines

http://poj.org/problem?id=3668

水题,STL

 1 #include <stdio.h>
 2 #include <set>
 3 
 4 using namespace std;
 5 
 6 set<pair<int, int> > set1;
 7 
 8 int gcd(int x, int y)
 9 {
10     return y? gcd(y, x%y): x;
11 }
12 
13 int abs(int x)
14 {
15     return x<0? -1*x: x;
16 }
17 
18 struct P
19 {
20     int x, y;
21 }p[1234];
22 
23 int main()
24 {
25     int n, i, j;
26     int x, y, gcd_xy;
27     while(~scanf("%d", &n))
28     {
29         set1.clear();
30         for(i=1; i<=n; i++)
31         {
32             scanf("%d%d", &p[i].x, &p[i].y);
33         }
34         for(i=1; i<=n-1; i++)
35         {
36             for(j=i+1; j<=n; j++)
37             {
38                 x = p[i].x - p[j].x;
39                 y = p[i].y - p[j].y;
40                 if(x < 0)
41                 {
42                     x *= -1;
43                     y *= -1;
44                 }
45                 gcd_xy = gcd(abs(x), abs(y));
46                 x /= gcd_xy;
47                 y /= gcd_xy;
48                 if(x == 0)
49                 {
50                     y = 1;
51                 }
52                 if(y == 0)
53                 {
54                     x = 1;
55                 }
56                 //printf("%d %d : %d %d\n", i, j, x, y);
57                 set1.insert(make_pair(x, y));
58             }
59         }
60         printf("%d\n", (int)set1.size());
61     }
62     return 0;
63 }

 

posted @ 2013-07-27 19:32  Yuan1991  阅读(265)  评论(0编辑  收藏  举报