HDU 4946 Area of Mushroom(凸包)
来源:互联网 发布:尚硅谷佟刚ajax源码 编辑:程序博客网 时间:2024/06/11 17:00
传送门
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.
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).
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
30 0 31 1 22 2 10
Sample Output
Case #1: 100
题目大意:
有
解题思路
显然,达到无穷的点的学生速度一定是最快的,那么我们首先找出速度最快的点,然后在进行判断,发现如果其中一个点被其他点包围了,那么这样的点也不是无穷的,到这里就想到,只有凸包上的点才是符合条件的。有如下几种情况。
情况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;}
阅读全文
0 0
- HDU 4946 Area of Mushroom 凸包
- HDU 4946 Area of Mushroom 凸包
- hdu-4946 Area of Mushroom 凸包
- 【凸包】HDU 4946 Area of Mushroom
- HDU 4946 Area of Mushroom(凸包)
- hdu 4946 Area of Mushroom(凸包)
- 【HDU】4946 Area of Mushroom 凸包
- HDU 4946 Area of Mushroom (凸包)
- hdu 4946 Area of Mushroom 凸包
- hdu 4946 Area of Mushroom 计算几何(凸包)
- HDU 4946 Area of Mushroom(凸包)
- HDU 4946 Area of Mushroom (凸包)
- HDU 4946 - Area of Mushroom (计算几何 凸包)
- HDU 4946 Area of Mushroom(凸包)
- HDU 4946 Area of Mushroom(凸包)
- Hdu 1946 Area of Mushroom[凸包]
- HDU 4946 Area of Mushroom 凸包 第八次多校
- HDU 4946 Area of Mushroom 共线凸包
- Android Studio打包以及Gradle配置构建
- word 中简单插入美观的代码
- 基于CentOS7将Java应用生成docker镜像
- Excel-VBA: 复选框CheckBox是否选中
- 84、java的IO操作-转化流
- HDU 4946 Area of Mushroom(凸包)
- Hdu 4089 Activation 概率DP
- docker的下载安装和运行gitlab、rabbitmq的方式
- 【第七周项目4】队列数组
- 第一个wxWidgets程序-helloworld
- GitLab 简明安装配置指南
- char*A与A[]
- 在JSP里使用CKEditor和CKFinder
- MFC 服务管理