稳定凸包问题 要求每条边上至少有三个点,且对凸包上点数为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. asp.net使用My97 Date Picker时设置默认起始时间为n年之前的今天

    可以使用My97 Date Picker组件来收集用户输入的日期值. 首先下载该组件:http://www.my97.net/dp/index.asp放到自己的项目中. 然后在项目里面引用js和css ...

  2. BootstrapValidator验证表单用法

    引入文件 <link rel="stylesheet" href="css/bootstrap.css"/> <link rel=" ...

  3. Perl Sort函数用法总结和使用实例

    一) sort函数用法 sort LISTsort BLOCK LISTsort SUBNAME LIST sort的用法有如上3种形式.它对LIST进行排序,并返回排序后的列表.假如忽略了SUBNA ...

  4. Aspose.Cells 设置背景颜色

    很多小伙伴设置背景颜色都不起作用,特别提醒需要加入下面一行: style.Pattern = BackgroundType.Solid; Aspose.Cells.Style style = null ...

  5. Fighting Game

    感谢上外静中任淳同学提供   uses crt; label   h;         //h是重新开始游戏 const   y1=18;   y2=18;       //p1,p2的纵坐标 var ...

  6. 15. Linked List Cycle && Linked List Cycle II

    Linked List Cycle Given a linked list, determine if it has a cycle in it. Follow up: Can you solve i ...

  7. 37. Binary Tree Zigzag Level Order Traversal && Binary Tree Inorder Traversal

    Binary Tree Zigzag Level Order Traversal Given a binary tree, return the zigzag level order traversa ...

  8. Android UI 绘制过程浅析(一)LayoutInflater简介

    前言 这篇blog是我在阅读过csdn大牛郭霖的<带你一步步深入了解View>一系列文章后,亲身实践并做出的小结.作为有志向的前端开发工程师,怎么可以不搞懂View绘制的基本原理——简直就 ...

  9. 在php中写接口时 对json格式的转换 简单的方法

    方法 一 方法二 可以通过urlencode();遍历出来

  10. MSSQLSERVER之发布-分发-订阅

    一.环境 发布服务器 O S: Windows servier 2003 64位 Soft: Microsoft SqlServer 2008 R2 I P: 192.168.3.70 HOST-NA ...