题意:

  在二维平面上,给定n个人

  每个人的坐标和移动速度v

  若对于某个点,只有 x 能最先到达(即没有人能比x先到这个点或者同时到这个点)

  则这个点称作被x占有,若有人能占有无穷大的面积 则输出1 ,否则输出0

思路:

  1、把所有点按速度排个序,然后把不是最大速度的点去掉

  剩下的点才有可能是占有无穷大的面积

  2、给速度最大的点做个凸包,则只有在凸包上的点才有可能占有无穷大

  若一个位置有多个人,则这几个人都是不能占有无穷大的。

  凸包上边里共线的点是要保留的。

#易错点:

1.凸包边上要保留共线的点,最好采用水平排序(构造凸包前)

  2.对于去重点,必须在构造完凸包之后。

WA:构造凸包之前去重点(构造凸包的点不包括有重复的点)

#include<stdio.h>
#include<algorithm>
#include<fstream>
#include<string.h>
#include<iostream>
using namespace std;
const int MAX=;
struct point
{
int x;
int y;
int v;
int i;
}p[MAX],Ini[MAX],res[MAX];
int ans[MAX];
bool cmp(point A,point B)
{
if(A.y==B.y)return A.x<B.x;
return A.y<B.y;
}
bool cmp1(point A,point B)
{
if(A.v>B.v)return true;
if(A.v==B.v)
{
if(A.x<B.x)return true;
if(A.x==B.x&&A.y<B.y)return true;
}
return false;
}
int cross(point A,point B,point C)
{
return (B.x-A.x)*(C.y-A.y)-(C.x-A.x)*(B.y-A.y);
}
int Graham(point *p,int n)
{
//if (n<3)return n;
sort(p,p+n,cmp);
int i;
int top=;
for(i=;i<n;i++)
{
while(top>=&&cross(res[top-],res[top-],p[i])<)
top--;
res[top++]=p[i];
}
int t=top+;
for(i=n-;i>=;i--)
{
while(top>=t&&cross(res[top-],res[top-],p[i])<)
top--;
res[top++]=p[i];
}
/*for(i=0;i<top;i++)
printf("%d %d\n",res[i].x,res[i].y);*/
return top;
}
int main()
{
int n;
int i,j;
//ifstream cin("A.txt");
int __case=;
while(cin>>n&&n)
{
for(i=;i<n;i++)
{
cin>>Ini[i].x>>Ini[i].y>>Ini[i].v;
Ini[i].i=i;
}
sort(Ini,Ini+n,cmp1);
//cout<<Ini[i-1].x<<Ini[i-1].y;
int tmp=;
for(i=;i<n;i++)
{
if(Ini[].v==Ini[i].v)tmp++;
else break;
}
point po;
for(i=,j=;i<tmp;)
{
po=Ini[i];
if(i<tmp-&&Ini[i+].x==Ini[i].x&&Ini[i+].y==Ini[i].y)
{
while(i<tmp-&&Ini[i+].x==Ini[i].x&&Ini[i+].y==Ini[i].y)
i++;
}
else
{
p[j++]=po;
}
i++;
}
printf("Case #%d: ",++__case); int m=Graham(p,j); memset(ans,,sizeof(ans));
for(i=;i<m;i++)
{
//printf("%d %d %d",res[i].x,res[i].y,res[i].v);
if(res[i].v>)
{
ans[res[i].i]=;
}
}
for(i=;i<n;i++)
printf("%d",ans[i]);
printf("\n");
}
return ;
}

WA:构造凸包之后去重点

#include<stdio.h>
#include<algorithm>
#include<fstream>
#include<string.h>
#include<iostream>
using namespace std;
const int MAX=;
struct point
{
int x;
int y;
int v;
int i;
int tmp;
} Ini[MAX],res[MAX];
bool flag[MAX];
int ans[MAX];
bool cmp(point A,point B)
{
if(A.y==B.y)return A.x<B.x;
return A.y<B.y;
}
bool cmp1(point A,point B)
{
if(A.v>B.v)return true;
return false;
}
int cross(point A,point B,point C)
{
return (B.x-A.x)*(C.y-A.y)-(C.x-A.x)*(B.y-A.y);
}
int Graham(point *p,int n)
{
//if (n<3)return n;
sort(p,p+n,cmp);
memset(flag,false,sizeof(flag));
int i;
int top=;
for(i=; i<n; i++)
{
while(top>=&&cross(res[top-],res[top-],p[i])<)
top--; res[top++]=p[i];
res[top-].tmp=i;
}
for(i=;i<top;i++)
flag[res[i].tmp]=true; int t=top+;
for(i=n-; i>=; i--) //i>=0
{
while(top>=t&&cross(res[top-],res[top-],p[i])<)
top--;
if(!flag[i])res[top++]=p[i];
//if(i==0)top--;
}
/*for(i=0; i<top; i++)
printf("$%d %d\n",res[i].x,res[i].y);*/
return top;
}
int main()
{
int n;
int i,j;
//ifstream cin("A.txt");
int __case=;
while(cin>>n&&n)
{
for(i=; i<n; i++)
{
cin>>Ini[i].x>>Ini[i].y>>Ini[i].v;
Ini[i].i=i;
}
sort(Ini,Ini+n,cmp1);
//cout<<Ini[i-1].x<<Ini[i-1].y;
int tmp=;
for(i=; i<n; i++)
{
if(Ini[].v>&&Ini[].v==Ini[i].v)tmp++;
else break;
}
int m=Graham(Ini,tmp);
memset(ans,,sizeof(ans));
printf("Case #%d: ",++__case);
point po;
for(i=; i<m; i++)
{
po=res[i];
//printf("#%d %d %d\n",res[i].x,res[i].y,res[i].i);
if(i<m-&&res[i+].x==po.x&&res[i+].y==po.y)
{
while(i<m-&&res[i+].x==po.x&&res[i+].y==po.y)
i++;
}
else
ans[po.i]=;
}
for(i=; i<n; i++)
printf("%d",ans[i]);
printf("\n");
}
return ;
}

数据:


构造凸包之前去掉重点,保留相同点中的一个。

AC:

#include<stdio.h>
#include<algorithm>
#include<fstream>
#include<string.h>
#include<iostream>
using namespace std;
const int MAX=;
struct point
{
int x;
int y;
int v;
int i;
int tmp;
} Ini[MAX],res[MAX],p[MAX];
bool flag[MAX];
int ans[MAX];
bool cmp(point A,point B)
{
if(A.y==B.y)return A.x<B.x;
return A.y<B.y;
}
bool cmp1(point A,point B)
{
if(A.v>B.v)return true;
if(A.v==B.v)
{
if(A.x<B.x)return true;
if(A.x==B.x&&A.y<B.y)return true;
}
return false;
}
int cross(point A,point B,point C)
{
return (B.x-A.x)*(C.y-A.y)-(C.x-A.x)*(B.y-A.y);
}
int Graham(point *p,int n)
{
//if (n<3)return n;
sort(p,p+n,cmp);
memset(flag,false,sizeof(flag));
int i;
int top=;
for(i=; i<n; i++)
{
while(top>=&&cross(res[top-],res[top-],p[i])<)
{
top--;
}
res[top++]=p[i];
res[top-].tmp=i;
}
for(i=;i<top;i++)
flag[res[i].tmp]=true; int t=top+;
for(i=n-; i>=; i--) //i>=0
{
while(top>=t&&cross(res[top-],res[top-],p[i])<)
top--;
if(!flag[i])res[top++]=p[i];
//if(i==0)top--;
}
/*for(i=0; i<top; i++)
printf("$%d %d\n",res[i].x,res[i].y);*/
return top;
}
int main()
{
int n;
int i,j;
//ifstream cin("A.txt");
int __case=;
while(cin>>n&&n)
{
for(i=; i<n; i++)
{
cin>>Ini[i].x>>Ini[i].y>>Ini[i].v;
Ini[i].i=i;
}
sort(Ini,Ini+n,cmp1);
//cout<<Ini[i-1].x<<Ini[i-1].y;
int tmp=;
for(i=; i<n; i++)
{
if(Ini[].v>&&Ini[].v==Ini[i].v)tmp++;
else break;
} memset(ans,,sizeof(ans));
point po;
for(i=,j=;i<tmp;i++)
{
po=Ini[i];
//flag=1;
if(i<tmp-&&Ini[i+].x==po.x&&Ini[i+].y==po.y)
{
//flag=0;
while(i<tmp-&&Ini[i+].x==po.x&&Ini[i+].y==po.y)
{
ans[Ini[i].i]=-;
i++;
}
ans[Ini[i].i]=-;
}
p[j++]=po;
}
int m=Graham(p,j); printf("Case #%d: ",++__case);
for(i=; i<m; i++)
{
if(!ans[res[i].i])ans[res[i].i]=;
}
for(i=; i<n; i++)
{
if(ans[i]==)printf("");
else printf("");
}
printf("\n");
}
return ;
}

hdu 4946 Area of Mushroom (凸包,去重点,水平排序,留共线点)的更多相关文章

  1. HDU 4946 Area of Mushroom 凸包 第八次多校

    题目链接:hdu 4946 题意:一大神有N个学生,各个都是小神,大神有个二次元空间,每一个小神都有一个初始坐标,如今大神把这些空间分给徒弟们,规则是假设这个地方有一个人比谁都先到这,那么这个地方就是 ...

  2. HDU 4946 Area of Mushroom 凸包

    链接:pid=4946">http://acm.hdu.edu.cn/showproblem.php?pid=4946 题意:有n个人.在位置(xi,yi),速度是vi,假设对于某个点 ...

  3. hdu 4946 Area of Mushroom(凸包)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=4946 Area of Mushroom Time Limit: 2000/1000 MS (Java/Ot ...

  4. HDU 4946 Area of Mushroom(构造凸包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4946 题目大意:在一个平面上有n个点p1,p2,p3,p4....pn,每个点可以以v的速度在平面上移 ...

  5. HDU 4946 Area of Mushroom (几何凸包)

    题目链接 题意:给定n个人,每个人有一个速度v方向任意.如果平面中存在一个点只有某个人到达的时间最短(即没有人比这个人到的时间更短或相同),那么我们定义这个店归这个人管辖,现在问这些人中哪些人的管辖范 ...

  6. HDU 4946 Area of Mushroom 共线凸包

    题意是在二维平面上 给定n个人 每一个人的坐标和移动速度v 若对于某个点,仅仅有 x 能最先到达(即没有人能比x先到这个点或者同一时候到这个点) 则这个点称作被x占有 若有人能占有无穷大的面积 则输出 ...

  7. HDU 4946 Area of Mushroom(2014 Multi-University Training Contest 8)

    思路: 只有速度最大才有可能为1,速度不是最大肯定为0,那么就是 只需要操作那些速度最大的点,这些点求一个凸包,判断一下是不是在凸包边上即可. 有几个需要注意的地方: 1.最大速度如果为0   那么肯 ...

  8. HDU 4946 凸包

    给你n个点,具有速度,一个位置如果有其他点能够先到,则不能继续访问,求出里面这些点哪些点是能够无限移动的. 首先我们考虑到,一个速度小的和一个速度大的,速度小的必定只有固定他周围的一定区域是它先到的, ...

  9. HDU 4946 共线凸包

    题目大意: 一些点在一张无穷图上面,每个点可以控制一些区域,这个区域满足这个点到达这个区域的时间严格小于其他点.求哪些点能够控制无穷面积的区域. 题目思路: 速度小的控制范围一定有限. 速度最大当且仅 ...

随机推荐

  1. Zookeeper--集群管理

    Zookeeper--集群管理 在多台服务器组成的集群中,需要监控每台服务器的状态,一旦某台服务器挂掉了或有新的机器加入集群,集群都要感知到,从而采取相应的措施.一个主动的集群可以自动感知节点的死亡和 ...

  2. (转)用javamail发送带附件的邮件

    本文转载自:http://redleaf.iteye.com/blog/78217 mail.java 代码 package mail; import java.util.* ; import jav ...

  3. python 异常处理,约束

    异常处理: 在编程过程中为了增加友好性,在程序出现bug时一般不会将错误信息显示给用户,而是显示一个提示的页面. try: pass except Exception,ex: pass 例如: whi ...

  4. Java运算符 逻辑运算符 短路运算符

    &      与 两个运算数都为真时结果为真,只要有一个运算数为假结果就为假,否则就为真. true & true = true   true & false = false ...

  5. cinder-backup详细介绍

    首先介绍Snapshot snapshot可以为volume创建快照,快照中保存了volume当前的状态,此后可以通过snapshot回溯 主要采用了Copy On Write算法.进行快照时,不牵涉 ...

  6. 一些常用的centos命令,记忆下,属于常用的

    一些常用的centos命令,记忆下,属于常用的 查询内网IP hostname -I 查询外网IP curl ifconfig.me 查看硬盘使用情况 df -h 查看系统资源使用率 top 查看系统 ...

  7. 星型打分插件 bootstrap-rating-input

    最近帮人实现一个打分的功能,发现bootstrap-rating-input是个简单又好用的星型打分,我对其做了些定制,添加了分值说明,并修改了样式,毕竟 bootstrap 自身的黑色五角星还是不够 ...

  8. Netty心跳简单Demo

    前面简单地了解了一下IdleStateHandler,我们现在写一个简单的心跳demo: 1)服务器端每隔5秒检测服务器端的读超时,如果5秒没有接受到客户端的写请求,也就说服务器端5秒没有收到读事件, ...

  9. Rhythmk 一步一步学 JAVA(4):Spring MVC -之拦截器

    1.实现拦截器类(myInterceptor): package com.rhythmk.Interceptor; import javax.servlet.http.HttpServletReque ...

  10. 初识Dash -- 构建一个人人都能够轻松上手的界面,操控数据和可视化

    从事数据科学工作,少不了使用Pandas.scikit-learn这些Python生态系统中的利器,还有就是控制工作流的Jupyter Notebooks,没的说,你和同事都爱用.但是,要想将工作成果 ...