Teacher Mai has a kingdom with the infinite area.ios
He has n students guarding the kingdom.less
The i-th student stands at the position (x i,y i), and his walking speed is v i.dom
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.this
For every student, Teacher Mai wants to know if the area in the charge of him is infinite.spa
There are multiple test cases, terminated by a line "0".code
For each test case, the first line contains one integer n(1<=n<=500).排序
In following n lines, each line contains three integers x i,y i,v i(0<=|x i|,|y i|,v i<=10^4).three
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".ip
3
0 0 3
1 1 2
2 2 1
0input
Case #1: 100
#include<iostream> #include<stdio.h> #include<stdlib.h> #include <iomanip> #include<cmath> #include<float.h> #include<string.h> #include<algorithm> #define sf scanf #define pf printf #define mm(x,b) memset((x),(b),sizeof(x)) #include<vector> #include<queue> #include<stack> #include<map> #define rep(i,a,n) for (int i=a;i<n;i++) #define per(i,a,n) for (int i=a;i>=n;i--) typedef long long ll; typedef long double ld; typedef double db; const ll mod=1e9+100; const db e=exp(1); const db eps=1e-8; using namespace std; const double pi=acos(-1.0); const int INF=0xfffffff; struct Point{ int x,y,num,temp1,temp2; }p[1007],s[1007],a[1007]; int direction(Point p1,Point p2,Point p3) { return (p3.x-p1.x)*(p2.y-p1.y)-(p2.x-p1.x)*(p3.y-p1.y); }//點2和3,按哪一個和點一的角度更小排,相同的話按哪一個更近排 double dis(Point p1,Point p2) { return sqrt((p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y)); } bool cmp(Point p1,Point p2)//極角排序 { int temp=direction(p[0],p1,p2); if(temp<0)return true ; if(temp==0&&dis(p[0],p1)<dis(p[0],p2))return true; return false; } int Graham(int n) { int top; int pos,minx,miny; minx=miny=INF; for(int i=0;i<n;i++)//找最下面的基點 if(p[i].y<miny||(p[i].y==miny&&p[i].x<minx)) { minx=p[i].x; miny=p[i].y; pos=i; } swap(p[0],p[pos]); sort(p+1,p+n,cmp); p[n]=p[0]; s[0]=p[0];s[1]=p[1];s[2]=p[2]; top=2; for(int i=3;i<=n;i++) { while(direction(s[top-1],s[top],p[i])>=0&&top>=2)top--; s[++top]=p[i] ; } return top; } int main() { int n,ans=1; while(1) { sf("%d",&n); if(!n) return 0; int Max=0; rep(i,0,n) { a[i].temp1=0;a[i].temp2=0; sf("%d%d%d",&a[i].x,&a[i].y,&a[i].num); Max=max(Max,a[i].num); } if(Max==0) { pf("Case #%d: ",ans++); rep(i,0,n) pf("0"); pf("\n"); continue; } rep(i,0,n) if(a[i].num==Max) a[i].temp1=1; rep(i,0,n) { if(a[i].num==Max) rep(j,0,n) { if(i!=j&&a[j].num==Max&&a[i].x==a[j].x&&a[i].y==a[j].y) { a[i].temp1=0;a[j].temp1=0; } } } int sum=0; rep(i,0,n) { if(a[i].num==Max) { int temp=0; rep(j,0,sum) if(a[i].x==p[j].x&&a[i].y==p[j].y) temp=1; if(temp==0) p[sum++]=a[i]; } } int top; top=Graham(sum); rep(i,0,top) { rep(j,0,n) { if(s[i].x==a[j].x&&s[i].y==a[j].y) a[j].temp2=1; if(direction(s[i],s[(i+1)%top],a[j])==0) a[j].temp2=1; } } pf("Case #%d: ",ans++); rep(i,0,n) if(a[i].temp1&&a[i].temp2) pf("1"); else pf("0"); pf("\n"); } }