稳定凸包问题 要求每条边上至少有三个点,且对凸包上点数为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. hmtl的标签属性

    html标签< <marquee>...</marquee>普通卷动 <marquee behavior=slide>...</marquee>滑 ...

  2. foreach属性-动态-mybatis中使用map类型参数,其中key为列名,value为列值

    http://zhangxiong0301.iteye.com/blog/2242723 最近有个需求,就是使用mybatis时,向mysql中插入数据,其参数为map类型,map里面的key为列名, ...

  3. ls

    -a, –all 列出目录下的所有文件,包括以 . 开头的隐含文件 -h, –human-readable 以容易理解的格式列出文件大小 (例如 1K 234M 2G) -l 除了文件名之外,还将文件 ...

  4. DB_MYSQL_mysql-5.7.10-winx64解压版安装笔记

    1.http://dev.mysql.com/downloads/mysql/ 里面下载Windows (x86, 64-bit), ZIP Archive mysql-5.7.10-winx64.z ...

  5. MyEclipse Spring 学习总结二 Bean的生命周期

    文件结构可以参考上一节 Bean的生命周期有方法有:init-method,destroy-method ApplicationContext.xml 文件配置如下: <?xml version ...

  6. localStorage兼容ie6/7 用addBehavior 实现

    制作过程我就不说了,程序下面会占出来 define(function(){ if('localStorage' in window) return; function Storage(){ this. ...

  7. 【java】 java 解压tar.gz读取内容

    package com.xwolf.stat.util; import com.alibaba.druid.util.StringUtils; import com.alibaba.fastjson. ...

  8. [Spring MVC] - @ModelAttribute使用

    在Spring MVC里,@ModelAttribute通常使用在Controller方法的参数注解中,用于解释model entity,但同时,也可以放在方法注解里. 如果把@ModelAttrib ...

  9. 6、java中的构造代码块

    /* 演示构造代码块的应用 */ class Person { String name; int age; //构造代码块 { cry(); } Person(String name, int age ...

  10. (C#) 求两个数组的交集

    基本上在面试的时候,会具体到两个int数组,或string数组.具体也就是讨论算法. 首先需要的是和面试的人确认题目的含义,并非直接答题. 然后,可以提出自己的想法,首先最快的是用linq { Lis ...