uva1606(极角扫描线)

题目连接:UVA - 1606

参考:http://www.cnblogs.com/AOQNRMGYXLMV/p/4277934.html

关于atan2和atan函数:http://blog.csdn.net/chinabinlang/article/details/6802686

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<cmath>
 5 #include<bits/stdc++.h>
 6 using namespace std;
 7 const int maxn=1010;
 8 int n,color[maxn];
 9 struct point
10 {
11     int x,y;
12     double rad;
13     point(int x=0,int y=0):x(x),y(y){}
14     bool operator<(const point& a) const
15     {
16         return rad<a.rad;
17     }
18 };
19 point op[maxn],p[maxn];
20 
21 point operator -(const point &a,const point &b)
22 {
23     return point(a.x-b.x,a.y-b.y);
24 }
25 
26 int cross(const point& a,const point &b)
27 {
28     return a.x*b.y-a.y*b.x;
29 }
30 
31 int solve()
32 {
33     int ans=0;
34     for(int i=0;i<n;i++)  //枚举基点
35     {
36         int k=0;
37         for(int j=0;j<n;j++) if(i!=j)
38         {
39             p[k]=op[j]-op[i];
40             if(color[j])  //将黑点中心对称
41             {
42                 p[k].x*=-1;
43                 p[k].y*=-1;
44             }
45             p[k].rad=atan2(p[k].y,p[k].x);
46             k++;
47         }
48         sort(p,p+k);
49         int l=0,r=0,cnt=2;
50         for(;l<k;l++)
51         {
52             if(l==r)
53             {
54                 r=(r+1)%k;
55                 cnt++;
56             }
57             while(l!=r&&cross(p[l],p[r])>=0)
58             {
59                 r=(r+1)%k;
60                 cnt++;
61             }
62             cnt--;
63             ans=max(ans,cnt);
64         }
65     }
66 
67     return ans;
68 }
69 
70 int main()
71 {
72     while(scanf("%d",&n)&&n)
73     {
74         for(int i=0;i<n;i++)
75             scanf("%d%d%d",&op[i].x,&op[i].y,&color[i]);
76         printf("%d\n",solve());
77     }
78 }

 

lrj238

posted @ 2017-05-01 21:49  yijiull  阅读(132)  评论(0编辑  收藏  举报