链接:http://acm.hdu.edu.cn/showproblem.php?pid=4946

Area of Mushroom

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1896    Accepted Submission(s): 452

Problem Description
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.

 
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).

 
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
 
Source

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

直接引用这里了:http://blog.csdn.net/hcbbt/article/details/38582243

题意: 
给定n个人,每个人的坐标和移动速度v,若对于某个点,只有 x 能最先到达(即没有人能比x先到这个点或者同时到这个点),则这个点称作被x占有,若有人能占有无穷大的面积 则输出1 ,否则输出0。

分析: 
到最后只有速度最大的点才有可能获得无穷大的面积。所以只要考虑速度最大的点。 
很明显,只有这些点的凸包边上的点才能获得无穷大的面积。 
所以求凸包边上的点就行了。

有几个要注意的坑就是: 
1. 如果有点(x,y,v)都相同,那这个点是无法占领无限大的,但是不能不考虑这个点进行凸包,因为这个点会对其他点产生影响。 
2. 如果最大速度为0,那么每个点都不会动,所以就不用进行凸包了。

====================================================

多校的题目质量确实高,就这题来说,设了几个坑,最大速度为零的情况,以及三点共线的情况,还有三点在边界上的情况

凸包有两种构建方法,一个是用极角排序,再循环一次

二是直接坐标排序,循环两次

但是第一种情况,对于三点在边界上的情况会少了最后一个点

这也是为什么网上的题解差不多都是第二种方法的原因,第一种方法,如果想用的话,必须先建凸包,

再判断是否在凸包的两点之间那条线上,在的话就保留,当然,会费些时间

----------------------------------------------------------------------------------

第二种方法建凸包:

 #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <algorithm> using namespace std;
#define MAXX 1110
#define eps 1e-8 typedef struct point
{
double x;
double y;
int v;
int id;
} point; bool dy(double x,double y)
{
return x>y+eps;
}
bool xy(double x,double y)
{
return x<y-eps;
}
bool dyd(double x,double y)
{
return x>y-eps;
}
bool xyd(double x,double y)
{
return x<y+eps;
}
bool dd(double x,double y)
{
return fabs(x-y)<eps;
} double crossProduct(point a,point b,point c)
{
return (a.x-c.x)*(b.y-c.y)>(b.x-c.x)*(a.y-c.y);
}
double dist(point a,point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
} point p[MAXX];
point stk[MAXX];
int top; bool cmp(point a,point b)
{
if( dd(a.y,b.y))
return xy(a.x,b.x);
return xy(a.y,b.y);
} void Graham(int n)
{
top=;
sort(p,p+n,cmp);
if(n == )
{
top=-;
return ;
}
stk[]=p[];
if(n == )
{
top=;
return;
}
stk[]=p[];
if(n == )
{
top=;
return;
}
stk[]=p[];
for(int i=; i<n; i++)
{
while(top && crossProduct(p[i],stk[top],stk[top-]))
top--;
stk[++top]=p[i];
}
int len=top;
stk[++top]=p[n-];
for(int i=n-; i>=; i--)
{
while(top != len && crossProduct(p[i],stk[top],stk[top-]))
top--;
stk[++top]=p[i];
}
} int main()
{
int i,j,n,m;
int cas=; while(scanf("%d",&n)!=EOF && n)
{
point tmp[MAXX];
int mark[MAXX];
int maxx=;
memset(mark,,sizeof(mark)); for(i=; i<n ; i++)
{ scanf("%lf%lf%d",&tmp[i].x,&tmp[i].y,&tmp[i].v);
if(maxx < tmp[i].v)
{
maxx=tmp[i].v;
}
tmp[i].id=i;
}
if(maxx == )
{ printf("Case #%d: ",cas++);
for(i=; i<n; i++)
printf("%d",mark[i]);
printf("\n");
continue;
}
int id[MAXX];
memset(id,,sizeof(id));
for(i=; i<n; i++)
{ for(j=i+; j<n; j++)
{ if(tmp[i].x == tmp[j].x && tmp[i].y == tmp[j].y && tmp[i].v == tmp[j].v)
{ tmp[i].v=;
id[i]=id[j]=-;
}
}
}
int ss=;
for(i=; i<n; i++)
{ if(maxx == tmp[i].v)
{ p[ss++] = tmp[i];//can??
}
}
Graham(ss);
for(i=; i<=top; i++)
{ if(id[stk[i].id] != -)
{ id[stk[i].id] = ;
}
}
printf("Case #%d: ",cas++);
for(i=; i<n; i++)
printf("%d",id[i]>?:);
printf("\n");
}
return ;
} /*
5
0 0 6
3 3 6
1 1 6
0 3 6
3 0 6
Case #1: 11011
9
0 0 3
0 1 3
0 2 3
1 0 3
1 1 3
1 2 3
2 0 3
2 1 3
2 2 3
Case #2: 111101111
3
0 0 3
1 1 2
2 2 1
Case #3: 100
3
0 0 3
0 0 3
0 0 3
Case #4: 000
8
1 1 3
2 1 3
3 1 3
3 2 3
2 2 3
1 2 3
1 3 3
3 3 3
Case #5: 11110111
4
0 0 3
0 3 3
3 0 3
1 1 3
Case #6: 1110
6
0 0 1
-1 0 1
1 0 1
0 1 1
0 -1 1
0 -1 1
Case #7: 011100
*/

第一种方法建凸包但wa的:

 #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include<iostream>
#include <algorithm> using namespace std;
#define MAXX 1110
#define eps 1e-8 typedef struct point
{ double x;
double y;
int v;
int id;
} point; bool dy(double x,double y)
{
return x>y+eps;
}
bool xy(double x,double y)
{
return x<y-eps;
}
bool dyd(double x,double y)
{
return x>y-eps;
}
bool xyd(double x,double y)
{
return x<y+eps;
}
bool dd(double x,double y)
{
return fabs(x-y)<eps;
} double crossProduct(point a,point b,point c)
{ return (c.x-a.x)*(b.y-a.y)-(c.y-a.y)*(b.x-a.x);
}
double dist(point a,point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
} point p[MAXX];
point stk[MAXX];
int top; bool cmp(point a,point b)
{ double len=crossProduct(p[],a,b);
if(dd(len,0.0))
{ return xy(dist(p[],a),dist(p[],b));
}
return xy(len ,0.0);
} int Graham(int n)
{ int tmp=;
if(n<) return ;
for(int i=; i<n; i++)
{ if(xy(p[i].x,p[tmp].x) || dd(p[i].x,p[tmp].x) && xy(p[i].y,p[tmp].y))
tmp=i;
}
swap(p[],p[tmp]);
sort(p,p+n,cmp);
top=;
stk[]=p[];
stk[]=p[];
for(int i=; i<n; i++)
{
while(top && xy(crossProduct(stk[top],stk[top-],p[i]),0.0))
top--;
stk[++top]=p[i];//会少一个点
}
/*int len=top;
stk[++top] = p [n-2];
for(int i=n-3; i>=0; i--)
{
while(top != len && xy(crossProduct(stk [top],stk[top-1],p[i]),0.0))
top--;
stk[++top] = p[i];
}*/ return top;
} int main()
{ int i,j,n,m;
int cas=; while(scanf("%d",&n)!=EOF && n)
{
point tmp[MAXX];
int mark[MAXX];
int maxx=;
memset(mark,,sizeof(mark));
for(i=; i<n ; i++)
{ scanf("%lf%lf%d",&tmp[i].x,&tmp[i].y,&tmp[i].v);
if(maxx < tmp[i].v)
{
maxx=tmp[i].v;
}
tmp[i].id=i;
}
if(maxx == )
{
printf("Case #%d: ",cas++);
for(i=; i<n; i++)
printf("%d",mark[i]);
printf("\n");
continue;
}
int id[MAXX];
memset(id,,sizeof(id));
for(i=; i<n; i++)
{ for(j=i+; j<n; j++)
{
if(tmp[i].x == tmp[j].x && tmp[i].y == tmp[j].y &&tmp[i].v == tmp[j].v)
{
tmp[i].v=;
id[i]=id[j]=-;
}
}
}
int ss=;
for(i=; i<n; i++)
{
if(maxx == tmp[i].v)
{
p[ss++]=tmp[i];//can??
}
}
int top=Graham(ss);
for(i=; i<=top; i++)
{
if(id[stk[i].id] != -)
{
id[stk[i].id] = ;
}
}
printf("Case #%d: ",cas++);
for(i=; i<n; i++)
printf("%d",id[i]>?:);
printf("\n");
}
return ;
} /*
5
0 0 6
3 3 6
1 1 6 0 3 6
3 0 6
Case #1: 11011
9
0 0 3
0 1 3
0 2 3
1 0 3
1 1 3
1 2 3
2 0 3
2 1 3
2 2 3
Case #2: 111101111
3
0 0 3
1 1 2
2 2 1
Case #3: 100
3
0 0 3
0 0 3
0 0 3
Case #4: 000
8
1 1 3
2 1 3
3 1 3
3 2 3
2 2 3
1 2 3
1 3 3
3 3 3
Case #5: 11110111
4
0 0 3
0 3 3
3 0 3
1 1 3
Case #6: 1110
6
0 0 1
-1 0 1
1 0 1
0 1 1
0 -1 1
0 -1 1
Case #7: 011100
*/

网上找的第一种方法AC的:(希望原创别喷我)

 #include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include <iostream>
#define EPS 1e-8
#define eps 1e-8
using namespace std;
struct TPoint
{
double x,y;
int id,v;
}p[],s[],hull[],pp[];
double cross(TPoint a, TPoint b, TPoint c) {
return (b.x - a.x) * (c.y - a.y) - (c.x - a.x)*(b.y - a.y);
}
double dis(TPoint a,TPoint b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
bool graham_cmp(const TPoint &b, const TPoint &c) {
double tmp = cross(b, c, p[]);
if (tmp > EPS)
return true;
if (fabs(tmp) < EPS && (dis(b, p[]) < dis(c, p[])))
return true;
return false;
}
int graham_scan(TPoint hull[], int n) {
int top, i, k = ;
for (i = ; i < n; ++i)
if ((p[k].y - p[i].y > EPS)
|| (fabs(p[i].y - p[k].y) < EPS && p[k].x - p[i].x > EPS))
k = i;
swap(p[], p[k]);
sort(p + , p + n, graham_cmp);
hull[] = p[], hull[] = p[], hull[] = p[];
if (n < )
return n;
else
top = ;
for (i = ; i < n; ++i) {
while (top >= && cross(hull[top - ], hull[top - ], p[i]) < EPS)
--top;
hull[top++] = p[i];
}
return top;
}
bool bo[];
int ans[];
bool cmp(TPoint a,TPoint b)
{
return a.x<b.x-eps||(fabs(a.x-b.x)<eps&&a.y<b.y);
}
int main() {
int ri=,n;
while(scanf("%d",&n)&&n)
{
int maxn=;
for(int i=;i<n;++i)
ans[i]=;
for(int i=;i<n;++i)
{
scanf("%lf%lf%d",&s[i].x,&s[i].y,&s[i].v);
s[i].id=i;
maxn=std::max(maxn,s[i].v);
}
if(maxn==)
{
printf("Case #%d: ",++ri);
for(int i=;i<n;++i)
printf("");
puts("");
continue;
}
int tail=;
for(int i=;i<n;++i)
{
if(s[i].v==maxn&&maxn>)
{
pp[tail]=s[i];
p[tail++]=s[i];
}
}
sort(p,p+tail,cmp);
int kk=;
for(int i=;i<tail;++i)
if(i==tail-||fabs(p[i].x-p[i+].x)>eps||fabs(p[i].y-p[i+].y)>eps)
p[kk++]=p[i];
int h=graham_scan(hull,kk);
hull[h]=hull[];
for(int i=;i<tail;++i)
{
int flag=;
for(int j=;j<tail;++j)
if(i!=j&&fabs(pp[i].x-pp[j].x)<eps&&fabs(pp[i].y-pp[j].y)<eps)
{
flag=;
break;
}
if(flag)
{
ans[pp[i].id]=;
continue;
}
bool ok=false;
for(int j=;j<h;++j)
{
if(fabs(cross(pp[i],hull[j],hull[j+]))<eps)
ok=true;
}
if(ok)
ans[pp[i].id]=;
else
ans[pp[i].id]=;
}
printf("Case #%d: ",++ri);
for(int i=;i<n;++i)
printf("%d",ans[i]);
puts(""); }
}

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 题目大意:在一个平面上有n个点p1,p2,p3,p4....pn,每个点可以以v的速度在平面上移 ...

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

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

  5. HDU 4946 Area of Mushroom 共线凸包

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

  6. hdu 4946 Area of Mushroom (凸包,去重点,水平排序,留共线点)

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

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

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

  8. HDU 4946 凸包

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

  9. 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) ...

随机推荐

  1. html 复习

    通过几次修改网页的经历,发现相关基础知识之薄弱,不得不再次花时间复习一遍.希望这是最后一次. 一 通用声明 HTML5 <!DOCTYPE html> HTML 4.01 <!DOC ...

  2. python爬虫学习记录

    爬虫基础 urllib,urllib2,re都是python自带的模块 urllib,urllib2区别是urllib2可以接受一个Request类的实例来设置url请求的headers,即可以模拟浏 ...

  3. Java URLClassLoader和ClassLoader

    开始:看名字都带有ClassLoader,叫做类加载器,事实上是可以理解为动态的加载类,不过,也不是只能加载类,也可以加载其他形式的文件,比如说.properties属性文件. 区别:其实在两个类加载 ...

  4. JQUERY解析XML IE8的兼容问题

    var str="xml字符串"; alert($(str).find("Row").attr("Id")); 在IE8下,这段脚本无法运行 ...

  5. Oracle错误:ORA-01033

    Oracle错误:ORA-01033 错误编码:ORA-01033: ORACLE initialization or shutdown in progress 故障描述:因为移动了数据库文件([NA ...

  6. Codeforces 733C:Epidemic in Monstropolis(暴力贪心)

    http://codeforces.com/problemset/problem/733/C 题意:给出一个序列的怪兽体积 ai,怪兽只能吃相邻的怪兽,并且只有体积严格大于相邻的怪兽才能吃,吃完之后, ...

  7. windows7 安装 memcached

    下载 memcached 的 windows 稳定 memcached.exe 版本,然后解压到某个目录下面,这里放到了 D:\ApacheServer\memcached 找到 C:\Windows ...

  8. [算法][包围盒]AABB简单类

    头文件: #pragma once #include <iostream> //一个假的点类型 struct Vector3 { float x; float y; float z; }; ...

  9. MAVEN安装过程

    maven 的压缩包地址: http://pan.baidu.com/s/1kT4ckGf 第三方资源jar包地址:   http://pan.baidu.com/s/1i3vtgED

  10. JSTL,自定义一个标签的功能案例

    1.自定义一个带有两个属性的标签<max>,用于计算并输出两个数的最大值: 2.自定义一个带有一个属性的标签<lxn:readFile  src=“”>,用于输出指定文件的内容 ...