hdu 4946 2014 Multi-University Training Contest 8

Area of Mushroom

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2390    Accepted Submission(s): 578


Problem Description
Teacher Mai has a kingdom with the infinite area.

He has n students guarding the kingdom.

The i-th student stands at the position (xi,yi), and his walking speed is vi.

If a point can be reached by a student, and the time this student walking to this point is strictly less than other students, this point is in the charge of this student.

For every student, Teacher Mai wants to know if the area in the charge of him is infinite.
 

 

Input
There are multiple test cases, terminated by a line "0".

For each test case, the first line contains one integer n(1<=n<=500).

In following n lines, each line contains three integers xi,yi,vi(0<=|xi|,|yi|,vi<=10^4).
 

 

Output
For each case, output "Case #k: s", where k is the case number counting from 1, and s is a string consisting of n character. If the area in the charge of the i-th student isn't infinite, the i-th character is "0", else it's "1".
 

 

Sample Input
3 0 0 3 1 1 2 2 2 1 0
 

 

Sample Output
Case #1: 100
 

 

Author
xudyh
 

 

Source
 
简单凸包,但是!!调了好久!
首先凸包边上的点时可以算的,所以我算的两向量相乘等于0是可以加进去的,但是点有重复啊!所以两个点重复的时候会怎样?乘前面后面的都为0,即使后面的向量加进去之后是凹的。。所以必须判断下一个点是不是和前一个点重合,重合则删去,然后最后把有被重复的再删去。
  1 #include<iostream>
  2 #include<cstdio>
  3 #include<cstring>
  4 #include<vector>
  5 #include<cmath>
  6 #include<map>
  7 #include<algorithm>
  8 #define M(a,b) memset(a,b,sizeof(a))
  9 using namespace std;
 10 
 11 int n;
 12 
 13 struct Node
 14 {
 15     long long x,y;
 16     int num;
 17     int flag;
 18     int speed;
 19     Node(int x=0, int y=0):x(x),y(y){}
 20     bool operator < (const Node &rhs) const
 21     {
 22         if(x==rhs.x) return y<rhs.y;
 23         return x<rhs.x;
 24     }
 25 };
 26 
 27 int ans[506];
 28 
 29 long long cross(Node A, Node B) {return A.x*B.y-A.y*B.x;}
 30 
 31 typedef Node Vector;
 32 Vector operator+(Vector A,Vector B){return Vector(A.x+B.x,A.y+B.y);}
 33 Vector operator-(Node A,Node B){return Vector(A.x-B.x,A.y-B.y);}
 34 Vector operator*(Vector A,int p){return Vector(A.x*p,A.y*p);}
 35 Vector operator/(Vector A,int p){return Vector(A.x/p,A.y/p);}
 36 
 37 int tubao(Node* poin,int cn,Node* che)
 38 {
 39     sort(poin,poin+cn);
 40     int m = 0;
 41     for(int i = 0;i<cn;i++)
 42     {
 43         while(m>1&&(cross(che[m-1]-che[m-2],poin[i]-che[m-1])<0||(poin[i].x==che[m-1].x&&poin[i].y==che[m-1].y)))
 44         {
 45             //cout<<cross(che[m-1]-che[m-2],poin[i]-che[m-1])<<' '<<i<<'i'<<' '<<m<<'m'<<'!'<<endl;
 46             m--;
 47         }//cout<<cross(che[m-1]-che[m-2],poin[i]-che[m-1])<<' '<<i<<'i'<<' '<<m<<'m'<<endl;
 48         che[m++] = poin[i];
 49         //for(int i = 0;i<m;i++)
 50            //cout<<che[i].x<<' '<<che[i].y<<endl;
 51         //cout<<endl;
 52     }
 53     int k = m;
 54     for(int i = cn-2; i>=0 ;i--)
 55     {
 56         while(m>k&&(cross(che[m-1]-che[m-2],poin[i]-che[m-1])<0||(poin[i].x==che[m-1].x&&poin[i].y==che[m-1].y))) m--;
 57         che[m++] = poin[i];
 58     }
 59     if(cn>1) m--;
 60     return m;
 61 }
 62 
 63 int main()
 64 {
 65     int cas = 0;
 66     while(scanf("%d",&n)==1&&n!=0)
 67     {
 68         Node point[506],point1[506],ch[506];
 69         cas++;
 70         M(ans,0);
 71         int a;
 72         long long b,c;
 73         int maxv = -1;
 74         for(int i = 0;i<n;i++)
 75         {
 76             scanf("%I64d%I64d%d",&b,&c,&a);
 77             point[i].x = b;
 78             point[i].y = c;
 79             point[i].num = i;
 80             point[i].speed = a;
 81             point[i].flag = 0;
 82             if(a>maxv) maxv = a;
 83         }
 84         int cnt = 0;
 85         for(int i = 0;i<n;i++)
 86         {
 87             if(point[i].speed==maxv)
 88             {
 89                 point1[cnt] = point[i];
 90                 cnt++;
 91             }
 92         }
 93         sort(point1,point1+cnt);
 94         for(int i = 0;i<cnt-1;i++)
 95         {
 96             if(point1[i].x==point1[i+1].x&&point1[i].y==point1[i+1].y)
 97                 point1[i].flag = 1,point1[i+1].flag = 1;
 98         }
 99         int temm = tubao(point1,cnt,ch);
100         for(int i = 0;i<temm;i++)
101             {
102                 if(maxv==0)
103                     break;
104                 //cout<<ch[i].x<<' '<<ch[i].y<<'!'<<endl;
105                 if(ch[i].flag==0)
106                    ans[ch[i].num] = 1;
107             }
108         printf("Case #%d: ",cas);
109         for(int i = 0;i<n;i++)
110         {
111            printf("%d",ans[i]);
112         }
113         printf("\n");
114     }
115     return 0;
116 }

 

posted @ 2014-10-20 13:01  haohaooo  阅读(196)  评论(0编辑  收藏  举报