POJ 1228 - Grandpa's Estate 稳定凸包
稳定凸包问题 要求每条边上至少有三个点,且对凸包上点数为1,2时要特判
巨坑无比,调了很长时间= =
//POJ 1228
//稳定凸包问题,等价于每条边上至少有三个点,但对m = 1(点)和m = 2(线段)要特判
//AC 2016-10-15 #include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#define MAXN 1010 double sqr(double x){
return x * x;
} struct point{
int x, y;
point(){}
point(int X, int Y): x(X), y(Y){}
friend int operator ^ (const point &p1, const point &p2){
return p1.x *p2.y - p1.y * p2.x;
}
friend int operator * (const point &p1, const point &p2){
return p1.x *p2.x + p1.y * p2.y;
}
double norm(){
return sqrt(sqr(x) + sqr(y));
}
friend point operator >> (const point &p1, const point &p2){
return point(p2.x - p1.x, p2.y - p1.y);
}
friend bool operator < (const point &p1, const point &p2){
return (p1.x < p2.x)||(p1.x == p2.x)&&(p1.y < p2.y);
}
}pt[MAXN]; template <typename T>
void swap(T &a, T &b){
T t = a;
a = b;
b = t;
} template <typename T>
void BBS(T a[], int n){
for (int i = 0; i < n; i++)
for (int j = 0; j < i; j++)
if (a[i] < a[j]) swap(a[i], a[j]);
} bool stable_convex_hull(point p[], int n){
int res = 0, cur = 0, m = 0;
BBS(p, n);
while(1){
int tmp = - 1;
bool stable = 0;
for (int i = 0; i < n; i++)
if (i != cur)
if (!(tmp + 1)){
tmp = i, stable = 0;
}
else{
int det = (p[cur] >> p[i]) ^ (p[cur] >> p[tmp]);
if (det > 0){
tmp = i, stable = 0;
}
else if ((!det)&&((p[cur] >> p[i]) * (p[cur] >> p[tmp]) > 0)){
if ((p[cur] >> p[i]).norm() > (p[cur] >> p[tmp]).norm())
tmp = i;
stable = 1;
}
}
if (tmp + 1){
m++;
if (!stable)
return 0;
}
if (!tmp||!(tmp + 1)) return ((tmp + 1) && (m > 2));
cur = tmp;
}
} int main(){
int t, n;
freopen("fin.c", "r", stdin);
scanf("%d", &t);
while(t--){
scanf("%d", &n);
for (int i = 0; i < n; i++){
scanf("%d%d", &pt[i].x, &pt[i].y);
}
if (stable_convex_hull(pt, n)){
puts("YES");
}
else puts("NO");
}
}
POJ 1228 - Grandpa's Estate 稳定凸包的更多相关文章
- 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(凸包)
Grandpa's Estate Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11289 Accepted: 3117 ...
- POJ 1228 Grandpa's Estate 凸包 唯一性
LINK 题意:给出一个点集,问能否够构成一个稳定凸包,即加入新点后仍然不变. 思路:对凸包的唯一性判断,对任意边判断是否存在三点及三点以上共线,如果有边不满足条件则NO,注意使用水平序,这样一来共线 ...
- POJ 1228 Grandpa's Estate --深入理解凸包
题意: 判断凸包是否稳定. 解法: 稳定凸包每条边上至少有三个点. 这题就在于求凸包的细节了,求凸包有两种算法: 1.基于水平序的Andrew算法 2.基于极角序的Graham算法 两种算法都有一个类 ...
- POJ1228 Grandpa's Estate 稳定凸包
POJ1228 转自http://www.cnblogs.com/xdruid/archive/2012/06/20/2555536.html 这道题算是很好的一道凸包的题吧,做完后会加深对凸包的 ...
- 【POJ】1228 Grandpa's Estate(凸包)
http://poj.org/problem?id=1228 随便看看就能发现,凸包上的每条边必须满足,有相邻的边和它斜率相同(即共线或凸包上每个点必须一定在三点共线上) 然后愉快敲完凸包+斜率判定, ...
- 简单几何(求凸包点数) POJ 1228 Grandpa's Estate
题目传送门 题意:判断一些点的凸包能否唯一确定 分析:如果凸包边上没有其他点,那么边想象成橡皮筋,可以往外拖动,这不是唯一确定的.还有求凸包的点数<=2的情况一定不能确定. /********* ...
- poj - 1228 - Grandpa's Estate
题意:原来一个凸多边形删去一些点后剩n个点,问这个n个点能否确定原来的凸包(1 <= 测试组数t <= 10,1 <= n <= 1000). 题目链接:http://poj. ...
- Grandpa's Estate - POJ 1228(稳定凸包)
刚开始看这个题目不知道是什么东东,后面看了大神的题解才知道是稳定凸包问题,什么是稳定凸包呢?所谓稳定就是判断能不能在原有凸包上加点,得到一个更大的凸包,并且这个凸包包含原有凸包上的所有点.知道了这个东 ...
随机推荐
- Centreon 监控报警
1.系统更新:yum update 2.安装组件:yum install -y httpd php-pear php php-mysql php-gd php-ldap php-xml php-mbs ...
- @ResponseBody 返回中文乱码问题解决 spingmvc
<!-- UTF8解决乱码问题 --> <bean class="org.springframework.web.servlet.mvc.method.annotation ...
- 使用 Windows AIK 创建自定的客户端系统WIM文件
Windows 7/2008 的AIK 3.0下载页面:地址链接 1.8G [3.1补充包为1.4G] 安装3.0后,升级为3.1方法: xcopy E:\ "C:\Program File ...
- 【uTenux实验】集合点端口
这个是头一次接触的概念.比较不好理解.内核规范中的说明就要20页! 看了王总写的uTenux内核规范之后,有那么一点明白了但理解不深. 集合点端口就像每次工作前的收集情况会.首长下达收集情况指令,各个 ...
- java 进程启用远程查看
用jconsole 1.启动脚本增加: JAVA_OPTS="-Djava.net.preferIPv4Stack=true -Djava.rmi.server.hostname=192.1 ...
- DataTable排序(转)
DataTable 排序 DataRow[] rows = dataTable1.Select("", "ord asc"); DataTable t ...
- .net 使用ffmpeg.exe进行音频转码
#region 音频转换 private int AudioIntervalTime = 100, iAudio = 0; private string strPath = "D:\\web ...
- java堆内存和栈内存的处理
前段时间学习二叉树在处理删除操作的时候遇到一个头疼的问题:删除节点的时候明明已经置null了可树上该节点依旧存在,还必须执行node.father.left = null;才可以删除node节点,寻找 ...
- [DFNews] GetData也出取证软件了
从事计算机取证的应该都听说过MIP(Mount Image Pro).VFC仿真和Recover My Files,上述三个应用比较广泛的软件都是GetData公司的产品.GetData现在也推出了自 ...
- JNI常见错误整理
ndk开发常见错误1. android.mk文件不存在 $ ndk-buildAndroid NDK: Your APP_BUILD_SCRIPT points to an unknown file: ...