HDU 4946 Area of Mushroom 共线凸包
题意是在二维平面上
给定n个人
每一个人的坐标和移动速度v
若对于某个点,仅仅有 x 能最先到达(即没有人能比x先到这个点或者同一时候到这个点)
则这个点称作被x占有
若有人能占有无穷大的面积 则输出1 。否则输出0
思路:
1、把全部点按速度排个序。然后把不是最大速度的点去掉
剩下的点才有可能是占有无穷大的面积
2、给速度最大的点做个凸包,则仅仅有在凸包上的点才有可能占有无穷大
若一个位置有多个人,则这几个人都是不能占有无穷大的。
凸包上边里共线的点是要保留的,,
附赠一波数据
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
#define INF 999999999.9
#define PI acos(-1.0)
#define ll int
const int MAX_N = 507;
const double eps = 1e-6; struct Point {
int x, y, v;
int id;
Point () {}
Point (int _x, int _y, int _v, int _id) {
x = x, y = _y, v = _v, id = _id;
}
bool operator < (const Point &rhs) const {
if (x != rhs.x) return x < rhs.x;
return y < rhs.y;
}
}; int v[MAX_N];
bool vis[MAX_N];
int n, top;
int ans[MAX_N];
Point P[MAX_N], p1[MAX_N]; double cross(Point a, Point b, Point c) {
return (a.x - c.x) * (b.y - c.y) - (b.x - c.x) * (a.y - c.y);
} bool cmp(Point a, Point b) {
if (a.y == b.y) return a.x < b.x;
return a.y < b.y;
}
void graham() {
sort(p1, p1 + n, cmp);
top = 1;
for (int i = 0; i < 2; i++) v[i] = i;
for (int i = 2; i < n; i++) {
while (top > 0 && cross(p1[i], p1[v[top]], p1[v[top - 1]]) > 0) top--;
v[++top] = i;
}
int len = top;
v[++top] = n - 2;
for (int i = n - 3; i >= 0; i--) {
while (top > len && cross(p1[i], p1[v[top]], p1[v[top - 1]]) > 0) top--;
v[++top] = i;
}
} void Clear() {
memset(ans, 0, sizeof ans);
memset(p1, 0, sizeof p1);
memset(P, 0, sizeof P);
memset(v, 0, sizeof v);
memset(vis, 0, sizeof vis);
}
const int N = 505; struct E {
int x, y, v, id, ok;
}s[N];
vector<E> G;
bool cmp1(const E a, const E b) {
if(a.v != b.v) return a.v > b.v;
if(a.x != b.x) return a.x < b.x;
if(a.y != b.y) return a.y < b.y;
return a.id < b.id;
}
int nn;
void put(int ttop){
for(int i = 1; i <= nn; i ++) printf("%d", ans[i]);
puts("");
} int main() {
int cas = 0;
while(~scanf("%d", &nn), nn) {
Clear();
printf("Case #%d: ", ++cas);
memset(ans, 0, sizeof ans);
for(int i = 0; i < nn; i ++) {
scanf("%d%d%d", &s[i].x, &s[i].y, &s[i].v);
s[i].id = i+1;
s[i].ok = 1;
for(int j = 0; j < i; j++)
if(s[i].x==s[j].x && s[i].y==s[j].y && s[i].v==s[j].v)
{
s[i].ok = 0;
break;
}
}
sort(s, s + nn, cmp1);
if(s[0].v==0){put(12);continue;}
int ttop = 0;
while(ttop < nn && s[ttop].v == s[0].v) ttop ++;
//----------------------------
G.clear();
for(int i = 0; i < ttop; i++)if( s[i].ok ) G.push_back(s[i]);
bool gongxian = true;
int x = 0, y = 0;
for(int i = 1; i < ttop; i++)
{
if(s[i].x == s[i-1].x && s[i].y == s[i-1].y)continue;
if(x==0&&y==0) {
x = s[i].x-s[i-1].x;
y = s[i].y - s[i-1].y;
}
else if(s[i].x - s[i-1].x != x || s[i].y - s[i-1].y != y)
{
gongxian =false;
break;
}
}
if(G.size()<=2 || gongxian) {
for(int i = 0; i < G.size(); i++)
{
bool ok = true;
for(int j = 0; ok && j < ttop; j++)
if(G[i].id != s[j].id && G[i].x==s[j].x && G[i].y==s[j].y)
ok = false;
ans[G[i].id] = ok;
}
put(ttop); continue;
}
for(int i = 0; i < G.size(); i++)
{
p1[i].x = G[i].x;
p1[i].y = G[i].y;
p1[i].id = G[i].id;
}
n = G.size();
graham();
for(int i = 0; i <= top; i++)
{
bool ok = true;
for(int j = 0; ok && j < ttop; j++)
{
if(p1[v[i]].id != s[j].id && p1[v[i]].x==s[j].x && p1[v[i]].y==s[j].y)
ok = false;
}
ans[p1[v[i]].id] = ok;
}
put(ttop);
}
return 0;
}
/*
9
0 0 1
0 0 1
0 10 1
0 10 1
10 0 1
10 0 1
10 10 1
10 10 1
5 5 1 10
0 0 1
0 0 1
0 10 1
0 10 1
10 0 1
10 0 1
10 10 1
10 10 1
5 5 1
5 5 1 4
0 0 1
1 0 1
2 0 1
1 1 1 1
0 0 0 6
0 0 1
-1 0 1
1 0 1
0 1 1
0 -1 1
0 -1 1 6
0 0 1
-1 0 1
1 0 1
0 1 1
0 -1 1
0 -1 1 */
HDU 4946 Area of Mushroom 共线凸包的更多相关文章
- 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 (凸包,去重点,水平排序,留共线点)
题意: 在二维平面上,给定n个人 每个人的坐标和移动速度v 若对于某个点,只有 x 能最先到达(即没有人能比x先到这个点或者同时到这个点) 则这个点称作被x占有,若有人能占有无穷大的面积 则输出1 , ...
- HDU 4946 Area of Mushroom (几何凸包)
题目链接 题意:给定n个人,每个人有一个速度v方向任意.如果平面中存在一个点只有某个人到达的时间最短(即没有人比这个人到的时间更短或相同),那么我们定义这个店归这个人管辖,现在问这些人中哪些人的管辖范 ...
- HDU 4946 Area of Mushroom 凸包 第八次多校
题目链接:hdu 4946 题意:一大神有N个学生,各个都是小神,大神有个二次元空间,每一个小神都有一个初始坐标,如今大神把这些空间分给徒弟们,规则是假设这个地方有一个人比谁都先到这,那么这个地方就是 ...
- 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 凸包
链接:pid=4946">http://acm.hdu.edu.cn/showproblem.php?pid=4946 题意:有n个人.在位置(xi,yi),速度是vi,假设对于某个点 ...
- HDU 4946 Area of Mushroom(2014 Multi-University Training Contest 8)
思路: 只有速度最大才有可能为1,速度不是最大肯定为0,那么就是 只需要操作那些速度最大的点,这些点求一个凸包,判断一下是不是在凸包边上即可. 有几个需要注意的地方: 1.最大速度如果为0 那么肯 ...
- [hdu-4946] Area of Mushroom 计算几何 凸包
大致题意: 平面上有n个人,给你每个人的坐标和一个速度v,如果某个人比其他所有人都先到达某点,则该点就被这个人掌控,求谁掌控者无限大的面积. 首先 速度最大的人,抛弃其他人,速度小的人必定无法得到无限 ...
- HDU 4946 共线凸包
题目大意: 一些点在一张无穷图上面,每个点可以控制一些区域,这个区域满足这个点到达这个区域的时间严格小于其他点.求哪些点能够控制无穷面积的区域. 题目思路: 速度小的控制范围一定有限. 速度最大当且仅 ...
随机推荐
- GB2312简体中文编码表
GB2312简体中文编码表 code +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F A1A0 . . · ˉ ˇ ¨ " 々 — - | … ...
- HDU 3436 Queue-jumpers
题意: n个人站成一排 一開始是从1到n有序的 如今有三个操作 Top操作是将一个人排到队首 Query操作是询问某个人如今排第几 Rank操作是询问排某个位置的人是谁 思路: 将队伍扭来扭 ...
- 关于comparator接口和comparable接口以及它们各自的方法compare()和compareTo()
在今天做的LeetCode的题中有两道都出现了利用接口实现对象的排序.两题的相关链接: 1.利用comparable接口对对象排序 2.利用comparator接口实现排序 因为之前都没接触过这两个接 ...
- 数学图形(2.17)pappus螺线
帕波斯(Pappus of Alexandria) 生于亚历山大,活跃于公元300—350前后.该螺线是一种绕在圆锥上的曲线. #http://www.mathcurve.com/courbes3d/ ...
- SpringMVC的学习
在看<跟开涛学SpringMVC.pdf> /Users/baidu/Documents/Data/Interview/Java Spring Web MVC 也是服务到工作者模式的实现, ...
- Linux使用sar进行性能分析
转:https://blog.csdn.net/xusensen/article/details/54606401#sar%E7%AE%80%E4%BB%8B Linux使用sar进行性能分析 Lin ...
- java实现双向循环链表
java实现循环链表:http://www.cnblogs.com/lixiaolun/p/4643911.html 在单链表中,查询下一个元素的时间是O(1).查询上一个元素的时间却是O(n). 为 ...
- 算法笔记_145:拓扑排序的应用(Java)
目录 1 问题描述 2 解决方案 1 问题描述 给出一些球,从1~N编号,他们的重量都不相同,也用1~N标记加以区分(这里真心恶毒啊,估计很多WA都是因为这里),然后给出一些约束条件,< a ...
- Java版 数字金额大写转换
需求:读入一个浮点数值,将其转化为中文金额的大写形式.如123.45,转化为:壹佰贰拾叁元肆角伍分. 以下是各种情况要完善: 1. 当金额为整数,只表示整数部分,省略小数部分,并添加“整”字.如123 ...
- vue 父子组件传值的另外一种方式 provide inject
1.文档说明 https://cn.vuejs.org/v2/api/#provide-inject 2.实例 element ui的dropdown组件 dropdown.vue: provide( ...