HDU 4946 Area of Mushroom 凸包
链接: pid=4946">http://acm.hdu.edu.cn/showproblem.php?pid=4946
题意:有n个人。在位置(xi,yi),速度是vi,假设对于某个点一个人比全部其它的都能先到那个点,那这个点就被这个人承包了。输出有多少人承包的(鱼塘)面积是无穷大。
思路:找出速度最大值,仅仅有速度是这个最大值的人才有可能承包无穷大的面积(由于快速者早晚会追上低速者)。
每两个人相比,他们能承包的位置的界线是他们坐标的中垂线,能够证明的是,在组成凸包时,在凸包里的人。承包的面积一定是有限的。
所以在凸包上的人(包含边上)才可能承包无穷大的面积。
注意点在于由于题里要求严格小于其它人到达的时间才干承包,所以假设出现重点重速的两个人,那么两个人都是不能承包的,可是在计算凸包时它们须要计进来由于有可能由于他们的存在导致其它人承包不了。
代码:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ctype.h>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define eps 1e-10
#define INF 0x7fffffff
#define maxn 10005
#define PI acos(-1.0)
#define seed 31//131,1313
typedef long long LL;
typedef unsigned long long ULL;
using namespace std;
int x[505],y[505],v[505],vis[505];
int cmp(double x)
{
if(fabs(x)<eps)
return 0;
if(x>0)
return 1;
return -1;
}
inline double sqr(double x)
{
return x*x;
}
struct point//点
{
double x,y;
int pos;
int o;
point() {}
point(double a,double b):x(a),y(b) {}
void input()
{
scanf("%lf%lf",&x,&y);
}
friend point operator + (const point &a,const point &b)
{
return point(a.x+b.x,a.y+b.y);
}
friend point operator - (const point &a,const point &b)
{
return point(a.x-b.x,a.y-b.y);
}
friend bool operator == (const point &a,const point &b)
{
return cmp(a.x-b.x)==0 &&cmp(a.y-b.y)==0;
}
friend point operator * (const point &a,const double &b)
{
return point(a.x*b,a.y*b);
}
friend point operator * (const double &a,const point &b)
{
return point(a*b.x,a*b.y);
}
friend point operator / (const point &a,const double &b)
{
return point(a.x/b,a.y/b);
}
double norm()
{
return sqrt(sqr(x)+sqr(y));
}//到原点距离
void out () const
{
printf("%.2f %.2f",x,y);
}
} p[505];
double det (const point &a,const point &b)
{
return a.x*b.y-a.y*b.x;
}//叉积
double dot (const point &a,const point &b)
{
return a.x*b.x+a.y*b.y;
}//点乘
double dist (const point &a,const point &b)
{
return (a-b).norm();
}//距离
point rotate_point(const point &p,double A)
{
double tx=p.x,ty=p.y;
return point (tx*cos(A)-ty*sin(A),tx*sin(A)+ty*cos(A));
}//旋转,A是弧度
struct polygon_convex
{
vector <point> P;
polygon_convex(int size=0)
{
P.resize(size);
}
} p_c;
bool comp_less(const point &a,const point &b)
{
return cmp(a.x-b.x)<0||cmp(a.x-b.x)==0&&cmp(a.y-b.y)<0;
}
polygon_convex convex_hull(vector <point> a)
{
polygon_convex res(2*a.size()+5);
sort(a.begin(),a.end(),comp_less);
a.erase(unique(a.begin(),a.end()),a.end());
int m=0;
for(int i=0; i<a.size(); i++)
{
while(m>1 && cmp(det(res.P[m-1]-res.P[m-2],a[i]-res.P[m-2]))<0)
m--;
res.P[m++]=a[i];
}
int k=m;
for(int i=int(a.size())-2; i>=0; i--)
{
while(m>k && cmp(det(res.P[m-1]-res.P[m-2],a[i]-res.P[m-2]))<0)
m--;
res.P[m++]=a[i];
}
res.P.resize(m);
if(a.size()>1)
res.P.resize(m-1);
return res;
}
bool cmp3(point a,point b)
{
return a.x<b.x||((a.x==b.x)&&(a.y<b.y));
}
int main()
{
int T,tt=0;
while(scanf("%d",&T))
{
tt++;
vector<point>pp;
pp.clear();
memset(vis,0,sizeof(vis));
if(T==0)
break;
int pos=-1;
int max_v=0;
for(int i=1; i<=T; i++)
{
scanf("%d%d%d",&x[i],&y[i],&v[i]);
if(v[i]>max_v)
max_v=v[i];
}
int top=0;
for(int i=1; i<=T; i++)
{
if(v[i]==max_v)
{
p[top].x=(double)x[i];
p[top].y=(double)y[i];
p[top].pos=i;
p[top].o=0;
top++;
}
}
printf("Case #%d: ",tt);
if(max_v==0)
{
for(int i=1; i<=T; i++)
printf("0");
printf("\n");
continue;
}
sort(p,p+top,cmp3);
for(int i=0; i<top; i++)
{
if((i<top-1&&(p[i].x)==(p[i+1].x)&&(p[i].y)==(p[i+1].y))||(i>0&&(p[i].x)==(p[i-1].x)&&(p[i].y)==(p[i-1].y)))
p[i].o=1;
}
pp.push_back(p[0]);
for(int i=1; i<top; i++)
{
if(p[i].x!=p[i-1].x||p[i].y!=p[i-1].y)
pp.push_back(p[i]);
}
if(pp.size()<=3)
{
for(int i=0; i<pp.size(); i++)
if(pp[i].o==0)
vis[pp[i].pos]=1;
}
else
{
polygon_convex ans=convex_hull(pp);
for(int i=0; i<ans.P.size(); i++)
{
if(ans.P[i].o==0)
vis[ans.P[i].pos]=1;
}
}
for(int i=1; i<=T; i++)
printf("%d",vis[i]);
printf("\n");
}
return 0;
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
HDU 4946 Area of Mushroom 凸包的更多相关文章
- HDU 4946 Area of Mushroom 凸包 第八次多校
题目链接:hdu 4946 题意:一大神有N个学生,各个都是小神,大神有个二次元空间,每一个小神都有一个初始坐标,如今大神把这些空间分给徒弟们,规则是假设这个地方有一个人比谁都先到这,那么这个地方就是 ...
- 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 (凸包,去重点,水平排序,留共线点)
题意: 在二维平面上,给定n个人 每个人的坐标和移动速度v 若对于某个点,只有 x 能最先到达(即没有人能比x先到这个点或者同时到这个点) 则这个点称作被x占有,若有人能占有无穷大的面积 则输出1 , ...
- HDU 4946 Area of Mushroom(2014 Multi-University Training Contest 8)
思路: 只有速度最大才有可能为1,速度不是最大肯定为0,那么就是 只需要操作那些速度最大的点,这些点求一个凸包,判断一下是不是在凸包边上即可. 有几个需要注意的地方: 1.最大速度如果为0 那么肯 ...
- HDU 4946 凸包
给你n个点,具有速度,一个位置如果有其他点能够先到,则不能继续访问,求出里面这些点哪些点是能够无限移动的. 首先我们考虑到,一个速度小的和一个速度大的,速度小的必定只有固定他周围的一定区域是它先到的, ...
- hdu 4946 2014 Multi-University Training Contest 8
Area of Mushroom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
随机推荐
- 浅析ArrayList,LinkedList的执行效率
以前见过很多文章说这两个东西,感觉自己还是没有深入理解,今天看了书明白一些,在此提出来和大家共同探讨: 面试的时候(基础)一般会问你使用过LinkedList或者ArrayList没有,简单的回答有或 ...
- 新版SDK自己主动加入PlaceholderFragment的思考
自从Android SDK更新到22.6.3,发现新建Activity的时候,会自己主动生成一个Fragment.这个Fragment是activity的静态内部类.同一时候生成了一个xml叫frag ...
- .Net C# Windows Service于server无法启动,错误 193:0xc1
1.情况说明:的近期发展windows维修,当地win7系统正常.把server安装会失败. 图中的引导失败的例子.: 解决方法:执行->输入:eventvwr.msc 打开你的事件查看器 ...
- JAVA的class打包成dll
一.将已经编译后的java中Class文件进行打包:打包命令JAR 如:将某目录下的所有class文件夹全部进行打包处理: 使用的命令:jar cvf test.jar -C com/ . //注意这 ...
- SWT的选择文件和文件夹的函数
org.eclipse.swt.widgets.DirectoryDialog//选择目录org.eclipse.swt.widgets.FileDialog//SWT.OPEN打开文件 SWT.SA ...
- ubuntu软件中心崩溃
网上找了下别人的解决方法(本人測试成功解决此问题): 提示说是lists出错 我的正是这样的情况 使用例如以下命令能够修复: 1.删除lists sudo rm /var/lib/apt/lists/ ...
- 同时显示多个 Notification
主要出在PendingIntent.getActivity();的第二个参数,API文档里虽然说是未被使用的参数(给出的例子也直接写0的),实际上是通过该参数来区别不同的Intent的,如果id相同, ...
- 一个非常优秀的前端框架--BootStrap
在接触BootStrap之前,也许我们已经度过了很多关于前端开发的框架及
- 【ThinkingInC++】61、非成员运算符
非成员运算符 当操作者的左侧是不同的类时.运算符重载不可能是正确的类中. IostreamOperatorOverloading.cpp /** * 书本:[ThinkingInC++] * 功能:非 ...
- GPS 偏移校正(WGS-84) 至(GCJ-02) java版本号以实现
public class EvilTransform { final static double pi = 3.14159265358979324; // // // a = 6378245.0, 1 ...