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 共线凸包
题目大意: 一些点在一张无穷图上面,每个点可以控制一些区域,这个区域满足这个点到达这个区域的时间严格小于其他点.求哪些点能够控制无穷面积的区域. 题目思路: 速度小的控制范围一定有限. 速度最大当且仅 ...
随机推荐
- eclipse中配置struts2出现There is no Action mapped for namespace [/] and action name [Login] associated wi
下午在eclipse中配置struts2时报: There is no Action mapped for namespace [/] and action name [Login] associat ...
- Debian学习笔记
14.1. 禁止非root用户登录系统 在/etc目录下新建一个nologin文本文件,内容随意.当系统发现该文件,就会禁止其它用户登录,并显示该文件内容. 14.2. 禁用CTRL+ALT+DEL组 ...
- [转载] 无所不能的“蚂蚁”--Ant
说他无所不能,好像有点夸张,但是用过Ant之后,感觉真的是只有想不到没有作不到.Ant,原作者选择他作为软件名字的意思是指"令一个简洁的工具"(Another Neat Tool) ...
- debian下安装mysql
apt-get install mysql-client mysql-server 中间会要你设置password,设置后后就自己主动启动mysql了 能够用ps -ef|grep mysql 这样能 ...
- iOS 改动toolbar里面文字的字体和大小
使用NSDictionaty来设置文本的属性: NSDictionary * attributes = @{NSFontAttributeName: [UIFont fontWithName:@&qu ...
- [Hive]使用HDFS文件夹数据创建Hive表分区
描写叙述: Hive表pms.cross_sale_path建立以日期作为分区,将hdfs文件夹/user/pms/workspace/ouyangyewei/testUsertrack/job1Ou ...
- whois协议
1.原理非常简单,域名的查询主要是基于RFC 954提供的WHOIS协议.在上述过程中,我们实际上是访问了InterNIC站点的WHOIS服务器,该服务器从WHOIS数据库中查询我们所需要的内容.WH ...
- RxJava 和 RxAndroid (生命周期控制和内存优化)
RxJava使我们很方便的使用链式编程,代码看起来既简洁又优雅.但是RxJava使用起来也是有副作用的,使用越来越多的订阅,内存开销也会变得很大,稍不留神就会出现内存溢出的情况,这篇文章就是介绍Rxj ...
- 使用OctreeQuantizer提高gdi+绘图质量
.net中gdi+绘制的图形质量很少,原因是gdi+使用的是256色的. 为了提高绘制图片的质量,可以使用是“Octree“ 算法.“Octree“ 算法允许我们插入自己的算法来量子化我们的图像. 一 ...
- M.2接口NVMe协议的固态硬盘读写速度是SATA接口的两倍
原文:https://www.sohu.com/a/203688929_615464 中午走路的时候,同事说的,M 2 nvme接口的更快. 树莓派开发板可以跑linux . ------------ ...