HDU 4946 Area of Mushroom(凸包)
Posted ITAK
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU 4946 Area of Mushroom(凸包)相关的知识,希望对你有一定的参考价值。
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.
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).
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
题目大意:
有
n
个学生,每个学生有坐标
解题思路
显然,达到无穷的点的学生速度一定是最快的,那么我们首先找出速度最快的点,然后在进行判断,发现如果其中一个点被其他点包围了,那么这样的点也不是无穷的,到这里就想到,只有凸包上的点才是符合条件的。有如下几种情况。
情况1: 当最快速度是
情况2: 当最快的点在凸包上的边上,我们需要判断,用叉积判断是不是共线。
情况3: 还有重点的时候,因为是严格最快的,所以当有重点,而且速度最快的时候,这样的点也是不符合的,输出
代码:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
struct Point
int x,y,w,flag,ind;
bool operator <(const struct Point &tmp)const
if(x-tmp.x == 0) return y<tmp.y;
return x<tmp.x;
bool operator ==(const struct Point &tmp)const
return x==tmp.x&&y==tmp.y&&w==tmp.w;
d[505],st[505];
bool cmp(Point a,Point b)
return a.w>b.w;
int XMulti(Point a, Point b, Point c)///ac X ab
return (c.x-a.x)*(b.y-a.y) - (b.x-a.x)*(c.y-a.y);
int ConvexHull(Point *p, int n, Point *st)///凸包
sort(p, p+n);
n=unique(p, p+n)-p;
int m = 0;
for(int i=0; i<n; i++)
while(m>1 && XMulti(st[m-2],p[i],st[m-1])<=0) m--;
st[m++] = p[i];
int k = m;
for(int i=n-2; i>=0; i--)
while(m>k && XMulti(st[m-2],p[i],st[m-1])<=0) m--;
st[m++] = p[i];
if(n > 1) m--;
return m;
int ans[505];
int main()
int n, cas=1;
while(~scanf("%d",&n))
if(n == 0)break;
for(int i=0;i<n;i++)
scanf("%d%d%d",&d[i].x,&d[i].y,&d[i].w);
d[i].ind=i;
for(int i=0; i<n; i++) d[i].flag=0;
for(int i=0; i<n; i++)
for(int j=i+1; j<n; j++)
if(d[i].x==d[j].x&&d[i].y==d[j].y&&d[i].w==d[j].w) d[i].flag=d[j].flag=1;
sort(d,d+n,cmp);
printf("Case #%d: ",cas++);
if(d[0].w == 0)
for(int i=0;i<n;i++) putchar('0');
puts("");
continue;
memset(ans, 0, sizeof ans);
int end2 = n;
for(int i=1; i<n; i++)
if(d[i].w != d[i-1].w)
end2=i;
break;
int cnt = ConvexHull(d, end2, st);
for(int i=0; i<end2; i++)
for(int j=0; j<cnt; j++)
if(!d[i].flag&&XMulti(d[i],st[j],st[(j+1)%cnt])==0) ans[d[i].ind] = 1;
for(int i=0; i<n; i++) printf("%d",ans[i]);
puts("");
return 0;
以上是关于HDU 4946 Area of Mushroom(凸包)的主要内容,如果未能解决你的问题,请参考以下文章