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(稳定凸包)
刚开始看这个题目不知道是什么东东,后面看了大神的题解才知道是稳定凸包问题,什么是稳定凸包呢?所谓稳定就是判断能不能在原有凸包上加点,得到一个更大的凸包,并且这个凸包包含原有凸包上的所有点.知道了这个东 ...
随机推荐
- css transform skew变换
两个参数,x-保持纵坐标不变,所有点旋转逆时针旋转x度,y-横坐标不变所有点顺时针旋转y度
- systemtap
http://www.ibm.com/developerworks/library/l-systemtap/index.html http://wiki.eclipse.org/Linux_Tools ...
- SQL server数据缓存依赖
SQL server数据缓存依赖有两种实现模式,轮询模式,通知模式. 1 轮询模式实现步骤 此模式需要SQL SERVER 7.0/2000/2005版本以上版本都支持 主要包含以下几 ...
- 解决IIS7该问.svc文件的错误问题
解决IIS7.5中部署WCF时,访问.svc文件的404错误问题如果你直接在IIS 7中配置WCF,访问.svc文件时会出现404错误.解决方法,以管理员身份进入命令行模式,运行:"%win ...
- Kafka安装及部署
安装及部署 一.环境配置 操作系统:Cent OS 7 Kafka版本:0.9.0.0 Kafka官网下载:请点击 JDK版本:1.7.0_51 SSH Secure Shell版本:XShell 5 ...
- 关于CGContextSetBlendMode: invalid context 0x0的错误
在ios 7的模拟器中,选择一个输入框准备输入时,会触发这个错误,以下是出错详细日志: <Error>: CGContextSetBlendMode: invalid context 0x ...
- ADF_Desktop Integration系列3_ADF桌面集成入门之重定义ADF Desktop Excel
2013-05-01 Created By BaoXinjian
- sudo执行脚本找不到环境变量
sudo执行脚本找不到变量 问题 当普通用户下,设置并export一个变量,然后利用sudo执行echo命令,能得到变量的值,但是如果把echo命令写入脚本,然后再sudo执行脚本,就找不到变量,未能 ...
- [ActionScript 3.0] AS3.0 让一个视频无缝循环播放的一个偏方
一个视频要循环播放,通常的办法都是播放完后再重新播放,但是不可避免的播放结束和重新开始播放这个时间点上会有停顿,如何解决这个问题,说个偏方吧! package com.views { import f ...
- CRM HomePage.aspx
//added by bgx on 20160616 //隐藏指定title按钮 function hideISVButton(buttonTitle) { var comps = document. ...