NCPC 2012 Galactic Warlords

湖南大学的oj上有这套比赛;

这题是个简单的计算几何,首先去掉重复的边,然后判断是否全部平行;

代码:

 1 #include<cstdio>
 2 #define maxn 105
 3 using namespace std;
 4  
 5 struct node
 6 {
 7     int x1,y1;
 8     int x2,y2;
 9 } no[maxn];
10  
11 bool cross(node a,node b)
12 {
13     int x=(b.x1-a.x1)*(a.y2-a.y1)-(b.y1-a.y1)*(a.x2-a.x1);
14     int y=(b.x2-a.x1)*(a.y2-a.y1)-(b.y2-a.y1)*(a.x2-a.x1);
15     if(x+y==0)return 0;
16     return 1;
17 }
18  
19 bool pall(node a,node b)
20 {
21     int nx1=a.x2-a.x1;
22     int ny1=a.y2-a.y1;
23     int nx2=b.x2-b.x1;
24     int ny2=b.y2-b.y1;
25     if(nx1*ny2==nx2*ny1)return 0;
26     return 1;
27 }
28  
29 int main()
30 {
31     int n,m;
32     while(scanf("%d%d",&n,&m)!=EOF)
33     {
34         bool flag2=1;
35         int cnt=0;
36         node a;
37         for(int i=0; i<m; i++)
38         {
39             bool flag1=0;
40             scanf("%d%d%d%d",&a.x1,&a.y1,&a.x2,&a.y2);
41             if(cnt==0)
42             {
43                 no[cnt++]=a;
44             }
45             else
46             {
47                 for(int i=0; i<cnt; i++)
48                 {
49                     if(cross(a,no[i])==0)
50                     {
51                         flag1=1;
52                         break;
53                     }
54                     if(pall(a,no[i])==1)flag2=0;
55                 }
56                 if(flag1==0)no[cnt++]=a;
57             }
58         }
59         int ans;
60         if(flag2==1)ans=cnt+1;
61         else ans=cnt*2;
62         if(ans>=n)puts("0");
63         else
64         {
65             if(flag2==1)
66             {
67                 if((cnt+1)*2>=n)puts("1");
68                 else printf("%d\n",(n-(cnt+1)*2-1)/2+2);
69             }
70             else printf("%d\n",(n-cnt*2-1)/2+1);
71         }
72     }
73     return 0;
74 }
View Code

 

posted @ 2013-10-26 19:27  Yours1103  阅读(273)  评论(0编辑  收藏  举报