POJ 1228 Grandpa's Estate 凸包 唯一性
题意:给出一个点集,问能否够构成一个稳定凸包,即加入新点后仍然不变。
思路:对凸包的唯一性判断,对任意边判断是否存在三点及三点以上共线,如果有边不满足条件则NO,注意使用水平序,这样一来共线点的包括也较为容易,而极角序对始边和终边的共线问题较为麻烦。
/** @Date : 2017-07-17 21:08:41
* @FileName: POJ 1228 稳定凸包.cpp
* @Platform: Windows
* @Author : Lweleth (SoungEarlf@gmail.com)
* @Link : https://github.com/
* @Version : $Id$
*/
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack>
#include <queue>
#include <math.h>
//#include <bits/stdc++.h>
#define LL long long
#define PII pair<int ,int>
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std; const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8; struct point
{
double x, y;
point(){}
point(double _x, double _y){x = _x, y = _y;}
point operator -(const point &b) const
{
return point(x - b.x, y - b.y);
}
double operator *(const point &b) const
{
return x * b.x + y * b.y;
}
double operator ^(const point &b) const
{
return x * b.y - y * b.x;
}
}; double xmult(point p1, point p2, point p0)
{
return (p1 - p0) ^ (p2 - p0);
} double distc(point a, point b)
{
return sqrt((double)((b - a) * (b - a)));
}
int sign(double x)
{
if(fabs(x) < eps)
return 0;
if(x < 0)
return -1;
else
return 1;
} ////////
int n;
point stk[N];
point p[N];
int cmp(point a, point b)//以p[0]基准 极角序排序
{
int t = xmult(a, b, p[0]);
if(t > 0)
return 1;
if(t == 0)
return distc(a, p[0]) < distc(b, p[0]);
if(t < 0)
return 0;
}
int cmpC(point a, point b)//水平序排序
{
return sign(a.x - b.x) < 0 || (sign(a.x - b.x) == 0 && sign(a.y - b.y) < 0);
}
int GrahamA()
{
double mix, miy;
mix = miy = 1e10;
int pos = 0;
for(int i = 0; i < n; i++)
{
if(p[i].y < miy || (p[i].y == miy && p[i].x < mix))
{
mix = p[i].x, miy = p[i].y;
pos = i;
}
}
swap(p[0], p[pos]);
sort(p + 1, p + n, cmp);
int top = 0;
stk[0] = p[0];
stk[1] = p[1];
for(int i = 0; i < n; i++)
{
while(top >= 2 && sign(xmult(stk[top - 2], stk[top - 1], p[i])) < 0)
top--;
stk[top++] = p[i];
}
//stk[++top] = p[0];
return top;
} int Graham()//水平序
{
sort(p, p + n, cmpC);
int top = 0;
for(int i = 0; i < n; i++)
{
while(top >= 2 && sign(xmult(stk[top - 2], stk[top - 1], p[i])) < 0)
top--;
stk[top++] = p[i];
}
int tmp = top;
for(int i = n - 2; i >= 0; i--)
{
while(top > tmp && sign(xmult(stk[top - 2],stk[top - 1] ,p[i] )) < 0)
top--;
stk[top++] = p[i];
}
if(n > 1)
top--;
return top;
} int check(int m)
{
//cout << m << endl;
for(int i = 1; i < m; i++)
{
//cout << i << endl;
//cout << "x:" << stk[i].x << "y:" << stk[i].y << endl;
//cout << xmult(stk[i - 1], stk[(i + 1)%(m)], stk[i]) << "~" << xmult(stk[i], stk[(i + 2)%(m)], stk[(i + 1)%(m)]) << endl; if(sign(xmult(stk[i - 1], stk[(i + 1)%(m)], stk[i])) != 0
&& sign(xmult(stk[i], stk[(i + 2)%(m)], stk[(i + 1)%(m)])) != 0)
return 0;
}
return 1;
}
/////////
int main()
{
int T;
cin >> T;
while(T--)
{
scanf("%d", &n);
for(int i = 0; i < n; i++)
{
double x, y;
scanf("%lf%lf", &x, &y);
p[i] = point(x, y);
}
if(n < 6)
{
printf("NO\n");
continue;
}
int cnt = Graham();
// for(int i = 0 ; i < cnt; i++)
// cout << stk[i].x << "%" << stk[i].y << endl;
printf("%s\n", check(cnt)?"YES":"NO"); }
return 0;
}
POJ 1228 Grandpa's Estate 凸包 唯一性的更多相关文章
- POJ 1228 Grandpa's Estate(凸包)
Grandpa's Estate Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11289 Accepted: 3117 ...
- POJ 1228 - Grandpa's Estate 稳定凸包
稳定凸包问题 要求每条边上至少有三个点,且对凸包上点数为1,2时要特判 巨坑无比,调了很长时间= = //POJ 1228 //稳定凸包问题,等价于每条边上至少有三个点,但对m = 1(点)和m = ...
- POJ 1228 Grandpa's Estate(凸包唯一性判断)
Description Being the only living descendant of his grandfather, Kamran the Believer inherited all o ...
- POJ 1228 Grandpa's Estate --深入理解凸包
题意: 判断凸包是否稳定. 解法: 稳定凸包每条边上至少有三个点. 这题就在于求凸包的细节了,求凸包有两种算法: 1.基于水平序的Andrew算法 2.基于极角序的Graham算法 两种算法都有一个类 ...
- 简单几何(求凸包点数) POJ 1228 Grandpa's Estate
题目传送门 题意:判断一些点的凸包能否唯一确定 分析:如果凸包边上没有其他点,那么边想象成橡皮筋,可以往外拖动,这不是唯一确定的.还有求凸包的点数<=2的情况一定不能确定. /********* ...
- poj - 1228 - Grandpa's Estate
题意:原来一个凸多边形删去一些点后剩n个点,问这个n个点能否确定原来的凸包(1 <= 测试组数t <= 10,1 <= n <= 1000). 题目链接:http://poj. ...
- 【POJ】1228 Grandpa's Estate(凸包)
http://poj.org/problem?id=1228 随便看看就能发现,凸包上的每条边必须满足,有相邻的边和它斜率相同(即共线或凸包上每个点必须一定在三点共线上) 然后愉快敲完凸包+斜率判定, ...
- 【POJ 1228】Grandpa's Estate 凸包
找到凸包后暴力枚举边进行$check$,注意凸包是一条线(或者说两条线)的情况要输出$NO$ #include<cmath> #include<cstdio> #include ...
- poj 1228 稳定凸包
Grandpa's Estate Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12337 Accepted: 3451 ...
随机推荐
- P4语法(4)Control block
Control block Control block之中用于放置设计好的Table和Action. 可以把control block认为是pipeline的一个模板,之前用的v1model中就是in ...
- struts2 不返回result的做法
有时候 比如提交一个弹框的表单 提交成功后我们只是让表单关闭并不进行页面跳转,那么action 里面就returne null, 然后result 也不用配置了 版权声明:本文为博主原创文章,未经博主 ...
- 使用kdump内核调试工具遇到的问题及解决
修改linux内核代码或者内核模块的时候,搞不好就会造成linux死机崩溃,crash死机后/var/log/kern.log里面不会有任何异常信息记录.这时候kdump就会派上用场了,网上kdump ...
- mosquitto启动时Address already in use 和 一般的 Address already in use
对于mosquitto启动时的地址占用错误,可能是mosquitto启动之后没关掉,进程一直占用了端口.查看mosquitto相关的进程,然后关掉就可启动了. 关掉mosquitto进程即可 参考: ...
- playbook详解—YAML格式的文本
在playbook中有一些核心的指令 hosts:指明命令运行在哪个node之上 remote_user:在远端的node之上以什么用户的身份运行命令 var:给模板传递变量值 tasks:指明需要执 ...
- Scrum Meeting Beta - 2
Scrum Meeting Beta - 2 NewTeam // 地点:新主楼F座二楼 任务反馈 团队成员 完成任务 计划任务 安万贺 了解缓存的相关内容Issue #109 设计本地存储的方案Is ...
- 【第八周】【新蜂】新NABCD
由小组成员宫成荣撰写 一.小组项目申请时提交的NABCD: 痛点:普通的俄罗斯方块是不现实距离下一级有多远的,我们的游戏能显示距离下一等级游戏有多远.方便玩家体验. nabc: n:能满足大多数玩家的 ...
- HDU 2164 Rock, Paper, or Scissors?
http://acm.hdu.edu.cn/showproblem.php?pid=2164 Problem Description Rock, Paper, Scissors is a two pl ...
- 面试- 阿里-. 大数据题目- 给定a、b两个文件,各存放50亿个url,每个url各占64字节,内存限制是4G,让你找出a、b文件共同的url?
假如每个url大小为10bytes,那么可以估计每个文件的大小为50G×64=320G,远远大于内存限制的4G,所以不可能将其完全加载到内存中处理,可以采用分治的思想来解决. Step1:遍历文件a, ...
- TDDL调研笔记
一,TDDL是什么 Taobao Distributed Data Layer,即淘宝分布式数据层,简称TDDL .它是一套分布式数据访问引擎 淘宝一个基于客户端的数据库中间件产品 基于JDBC规范, ...