稳定凸包问题 要求每条边上至少有三个点,且对凸包上点数为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 稳定凸包的更多相关文章

  1. POJ 1228 Grandpa's Estate(凸包唯一性判断)

    Description Being the only living descendant of his grandfather, Kamran the Believer inherited all o ...

  2. POJ 1228 Grandpa's Estate(凸包)

    Grandpa's Estate Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11289   Accepted: 3117 ...

  3. POJ 1228 Grandpa's Estate 凸包 唯一性

    LINK 题意:给出一个点集,问能否够构成一个稳定凸包,即加入新点后仍然不变. 思路:对凸包的唯一性判断,对任意边判断是否存在三点及三点以上共线,如果有边不满足条件则NO,注意使用水平序,这样一来共线 ...

  4. POJ 1228 Grandpa's Estate --深入理解凸包

    题意: 判断凸包是否稳定. 解法: 稳定凸包每条边上至少有三个点. 这题就在于求凸包的细节了,求凸包有两种算法: 1.基于水平序的Andrew算法 2.基于极角序的Graham算法 两种算法都有一个类 ...

  5. POJ1228 Grandpa's Estate 稳定凸包

    POJ1228 转自http://www.cnblogs.com/xdruid/archive/2012/06/20/2555536.html   这道题算是很好的一道凸包的题吧,做完后会加深对凸包的 ...

  6. 【POJ】1228 Grandpa's Estate(凸包)

    http://poj.org/problem?id=1228 随便看看就能发现,凸包上的每条边必须满足,有相邻的边和它斜率相同(即共线或凸包上每个点必须一定在三点共线上) 然后愉快敲完凸包+斜率判定, ...

  7. 简单几何(求凸包点数) POJ 1228 Grandpa's Estate

    题目传送门 题意:判断一些点的凸包能否唯一确定 分析:如果凸包边上没有其他点,那么边想象成橡皮筋,可以往外拖动,这不是唯一确定的.还有求凸包的点数<=2的情况一定不能确定. /********* ...

  8. poj - 1228 - Grandpa's Estate

    题意:原来一个凸多边形删去一些点后剩n个点,问这个n个点能否确定原来的凸包(1 <= 测试组数t <= 10,1 <= n <= 1000). 题目链接:http://poj. ...

  9. Grandpa's Estate - POJ 1228(稳定凸包)

    刚开始看这个题目不知道是什么东东,后面看了大神的题解才知道是稳定凸包问题,什么是稳定凸包呢?所谓稳定就是判断能不能在原有凸包上加点,得到一个更大的凸包,并且这个凸包包含原有凸包上的所有点.知道了这个东 ...

随机推荐

  1. UIApplication的使用

    //// UIApplication的使用//  IOS笔记////  Created by **** on ****.//  Copyright © 2013年 ***. All rights re ...

  2. javaScript DOM JQuery AJAX

    http://www.cnblogs.com/wupeiqi/articles/5369773.html 一 JavaScript JavaScript是一门编程语言,浏览器内置了JavaScript ...

  3. git相关

    进入到想要用git管理的project目录下 1.git init 意即该目录会被git监视一切的变动 同时生成一个.git文件夹下面存放了管理该project的一切必要信息 2.git add &l ...

  4. mac osx 制作安装u盘

    制作OS X El Capitan 原版安装U盘:sudo /Applications/Install\ OS\ X\ El\ Capitan.app/Contents/Resources/creat ...

  5. nodejs:express API之res.locals

    在从零开始nodejs系列文章中,有一个login.html文件 再来看它的get方法,我们并没有看到mess字段.那mess到底是从哪里来的呢? 接着我看到app.js文件里面: 只有这里出现了me ...

  6. WeX5学习笔记-建立项目且从SVN获取版本

    UI2项目(app项目)建立步骤: 1.从网上获得WeX5_V3.1.1.zip 文件,在某盘根目录下,创建一个文件,起名尽量短小,因开发包里的文件目录层次很深,有时会报路径长度超出范围的提示,如创建 ...

  7. 短作业优先调度算法(SJF)

    假设有n项作业位于就绪队列中,这些作业的提交时间用数组requestTimes按照提交时间的先后顺序存储,对应的作业服务时间(持续时间)用数组durations存储.采用SJF算法,计算n项作业的平均 ...

  8. Linux定时任务系统 Cron

    运行计划任务时:service crond restart提示:crond: unrecognized service安装计划任务:yum -y install vixie-cron 另外附计划任务的 ...

  9. 四则运算GUI设计

    使用了QT来设计GUI,目前也还在看视频学习中,目前还不会用这个软件,所以具体功能还未实现,初步绘制的界面如下:

  10. 无法连接远程SQL Server 数据库的原因

    1. tcp协议开启 2. 1433端口是否添加防火墙例外