Area of Mushroom
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 386 Accepted Submission(s): 55
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 (x i,y i), and his walking speed is v i.
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.
He has n students guarding the kingdom.
The i-th student stands at the position (x i,y i), and his walking speed is v i.
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 x i,y i,v i(0<=|x i|,|y i|,v i<=10^4).
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).
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
多校也快做完了。快结束了。总之感觉题目不会。很多题目都没思路,自己太嫩了,太水了。
今天是多校的第7场了。
直接把官方的解释放在这里吧。
当时比赛的时候想多了。哎!没想到就这么简单!简单的几何问题,套套模板就过的题呀!!可惜呀
之后AC的代码:
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<vector>
#include<sstream>
#include<cassert>
using namespace std;
#define LL __int64
#define eps 1e-6
struct point {
double x, y;
double v;
};
bool mult(point sp, point ep, point op) {
return(sp.x - op.x) * (ep.y - op.y)
>= (ep.x - op.x) * (sp.y - op.y);
}
bool operator< (const point &l, const point &r) {
return l.y < r.y || (l.y == r.y && l.x < r.x);
}
int graham(point pnt[], int n, point res[]) {
int i, len, k = 0, top = 1;
sort(pnt, pnt + n);
if(n == 0) return 0;
res[0] = pnt[0];
if(n == 1) return 1;
res[1] = pnt[1];
if(n == 2) return 2;
res[2] = pnt[2];
for(i = 2; i < n; i++) {
while(top && mult(pnt[i], res[top], res[top-1]))
top--;
res[++top] = pnt[i];
}
len = top;
res[++top] = pnt[n - 2];
for(i = n - 3; i >= 0; i--) {
while(top!=len && mult(pnt[i], res[top],
res[top-1])) top--;
res[++top] = pnt[i];
}
return top; // 返回凸包中点的个数
}
double xmulti(point p1,point p2,point p0) {
return((p1.x-p0.x) * (p2.y-p0.y) -
(p2.x-p0.x) * (p1.y-p0.y));
}
//确定两条线段是否相交
double mx(double t1,double t2) {
if(t1>t2) return t1;
return t2;
}
double mn(double t1,double t2) {
if(t1<t2) return t1;
return t2;
}
struct Llineseg {
point a,b;
};
int lsinterls(Llineseg u,Llineseg v) {
return( (mx(u.a.x,u.b.x)>=mn(v.a.x,v.b.x))&&
(mx(v.a.x,v.b.x)>=mn(u.a.x,u.b.x))&& (mx(u.a.y,u.b.y)>=mn(v.a.y,v.b.y))&& (mx(v.a.y,v.b.y)>=mn(u.a.y,u.b.y))&&
(xmulti(v.a,u.b,u.a)*xmulti(u.b,v.b,u.a)>=0)&&
(xmulti(u.a,v.b,v.a)*xmulti(v.b,u.b,v.a)>=0));
}
bool eque(point a,point b) {
if(a.x==b.x&&a.y==b.y&&a.v==b.v) {
return true;
}
return false;
}
bool eque1(point a,point b) {
if(a.x==b.x&&a.y==b.y) {
return true;
}
return false;
}
//判断点p是否在线段l上
int ponls(Llineseg l,point p) {
if(eque1(l.a,p)||eque1(l.b,p))
return 1;
return( (xmulti(l.b,p,l.a)==0) &&
( ((p.x-l.a.x)*(p.x-l.b.x)<0 ) ||((p.y-l.a.y)*(p.y-l.b.y)<0 )) );
}
point a[505];
point b[505];
int ans[505];
int main() {
int n;
double ma=0.0;
int tt=1;
while(cin>>n) {
ma=0.0;
if(n==0) break;
for(int i=0; i<n; i++) {
scanf("%lf %lf %lf",&a[i].x,&a[i].y,&a[i].v);
if(ma<a[i].v) {
ma=a[i].v;
}
}
// cout<<"ma=="<<ma<<endl;
printf("Case #%d: ",tt++);
int k=0;
//cout<<ma<<endl;
//memset(ans,0,sizeof(ans));
for(int i=0; i<n; i++) {
ans[i]=0;
}
if(fabs(ma-0.0)<=eps) {
for(int i=0; i<n; i++) {
cout<<ans[i];
}
cout<<endl;
continue;
}
for(int i=0; i<n; i++) {
if(a[i].v==ma) {
// ans[i]=1;
b[k++]=a[i];
}
}
point res[505];
Llineseg tem;
int n1=graham(b, k, res);
for(int i=0; i<n1; i++) {
tem.a=res[i];
tem.b=res[(i+1)%n1];
for(int j=0; j<n; j++) {
if(ponls(tem,a[j])&&a[j].v==ma) {
ans[j]=1;
}
}
}
// for(int i=0; i<n; i++) {
// printf("%d",ans[i]);
// }
// printf("\n");
for(int i=0; i<n; i++) {
if(a[i].v==ma)
for(int j=i+1; j<n; j++) {
if(eque(a[i],a[j])) {
ans[i]=0;
ans[j]=0;
}
}
}
for(int i=0; i<n; i++) {
printf("%d",ans[i]);
}
printf("\n");
}
return 0;
}
/*
3
1 1 2
2 2 2
3 3 3
3
1 1 2
2 2 2
3 3 2
3
1 1 2
2 2 2
3 3 3
*/