hdu 4946 Area of Mushroom (凸包,去重点,水平排序,留共线点)
题意:
在二维平面上,给定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 (凸包,去重点,水平排序,留共线点)的更多相关文章
- HDU 4946 Area of Mushroom 凸包 第八次多校
题目链接:hdu 4946 题意:一大神有N个学生,各个都是小神,大神有个二次元空间,每一个小神都有一个初始坐标,如今大神把这些空间分给徒弟们,规则是假设这个地方有一个人比谁都先到这,那么这个地方就是 ...
- HDU 4946 Area of Mushroom 凸包
链接:pid=4946">http://acm.hdu.edu.cn/showproblem.php?pid=4946 题意:有n个人.在位置(xi,yi),速度是vi,假设对于某个点 ...
- hdu 4946 Area of Mushroom(凸包)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4946 Area of Mushroom Time Limit: 2000/1000 MS (Java/Ot ...
- HDU 4946 Area of Mushroom(构造凸包)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4946 题目大意:在一个平面上有n个点p1,p2,p3,p4....pn,每个点可以以v的速度在平面上移 ...
- HDU 4946 Area of Mushroom (几何凸包)
题目链接 题意:给定n个人,每个人有一个速度v方向任意.如果平面中存在一个点只有某个人到达的时间最短(即没有人比这个人到的时间更短或相同),那么我们定义这个店归这个人管辖,现在问这些人中哪些人的管辖范 ...
- HDU 4946 Area of Mushroom 共线凸包
题意是在二维平面上 给定n个人 每一个人的坐标和移动速度v 若对于某个点,仅仅有 x 能最先到达(即没有人能比x先到这个点或者同一时候到这个点) 则这个点称作被x占有 若有人能占有无穷大的面积 则输出 ...
- HDU 4946 Area of Mushroom(2014 Multi-University Training Contest 8)
思路: 只有速度最大才有可能为1,速度不是最大肯定为0,那么就是 只需要操作那些速度最大的点,这些点求一个凸包,判断一下是不是在凸包边上即可. 有几个需要注意的地方: 1.最大速度如果为0 那么肯 ...
- HDU 4946 凸包
给你n个点,具有速度,一个位置如果有其他点能够先到,则不能继续访问,求出里面这些点哪些点是能够无限移动的. 首先我们考虑到,一个速度小的和一个速度大的,速度小的必定只有固定他周围的一定区域是它先到的, ...
- HDU 4946 共线凸包
题目大意: 一些点在一张无穷图上面,每个点可以控制一些区域,这个区域满足这个点到达这个区域的时间严格小于其他点.求哪些点能够控制无穷面积的区域. 题目思路: 速度小的控制范围一定有限. 速度最大当且仅 ...
随机推荐
- xshell连接kali
连接出现错误,连接不上去,看到一篇文章可以使用,https://blog.csdn.net/yemaxq/article/details/78171241
- SpringBoot中RedisTemplate订阅发布对象
解说 RedisMessageListenerContainer Redis订阅发布的监听容器,你的消息发布.订阅配置都必须在这里面实现 addMessageListener(MessageListe ...
- 模块初识import sys---- sys.argv--- import os---- os.system("df -h")
模块分2种,也叫库 1.标准库,直接导入import就可以用 2.第三方库,必须先安装再导入import才能使用 import sys print(sys.path) #打印环境变量 这边有一个注意事 ...
- cx_Oracle.DatabaseError: ORA-12541: TNS:no listener
问题:利用Python连接Oracle时报错,完整过程如下 import cx_Oracle conn = cx_Oracle.connect('testma/dingjia@192.168.88.1 ...
- 浅谈PHP面向对象编程(四、类常量和静态成员)
4.0 类常量和静态成员 通过上几篇博客我们了解到,类在实例化对象时,该对象中的成员只被当前对象所有.如果希望在类中定义的成员被所有实例共享. 此时可以使用类常量或静态成员来实现,接下来将针对类常量和 ...
- 【转】java与.net比较学习系列(3) 基本数据类型和类型转换
原文地址:https://www.cnblogs.com/mcgrady/p/3397874.html 阅读目录 一,整数类型 二,浮点数类型 三,字符类型 四,布尔类型 五,类型转换之自动转换 六, ...
- Python环境搭建之OpenGL
以下内容为我python OpenGl 环境搭建历程: win7 64位操作系统,python3.5.3 ,无其他相关. 直接cmd或PowerShell输入以下命令: pip install PyO ...
- git之常用命令
git之常用命令 1.下载远程仓库最新代码 $ git pull --rebase origin master 2.上传代码 $ git push origin master 3.退出编辑 ESC + ...
- Zabbix Proxy 分布式监控
简介: Zabbix 是一个分布式监控系统,它可以以一个中心点.多个分节点的模式运行,使用 proxy 能降低 Zabbix Server 的压力,当然也带来了成本~ 适用范围:跨机房.跨地域的网络监 ...
- C++ Assert()函数
assert宏的原型定义在<assert.h>中,其作用是如果它的条件返回错误,则终止程序执行,原型定义: #include <assert.h> void assert( i ...