http://poj.org/problem?id=1228

题目大意:给一个凸包,问是否为稳定凸包。

————————————————————————

稳定凸包的概念为:我任意添加一个点都不能使这个凸包得到扩充,这样的凸包为稳定凸包。

我们求完凸包后枚举边然后枚举有多少点在上面即可。

(网上的程序真的大部分是错的……)

#include<cstdio>
#include<queue>
#include<cctype>
#include<cstring>
#include<stack>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=;
struct point{
int x;
int y;
}p[N],q[N];
int n,per[N],l;
inline point getmag(point a,point b){
point s;
s.x=b.x-a.x;s.y=b.y-a.y;
return s;
}
inline int multiX(point a,point b){
return a.x*b.y-b.x*a.y;
}
inline int dis(point a,point b){
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
inline bool cmp(int u,int v){
int det=multiX(getmag(p[],p[u]),getmag(p[],p[v]));
if(det!=)return det>;
return dis(p[],p[u])<dis(p[],p[v]);
}
void graham(){
int id=;
for(int i=;i<=n;i++){
if(p[i].x<p[id].x||(p[i].x==p[id].x&&p[i].y<p[id].y))id=i;
}
if(id!=)swap(p[],p[id]);
for(int i=;i<=n;i++)per[i]=i;
sort(per+,per+n+,cmp);
l=;
q[++l]=p[];
for(int i=;i<=n;i++){
int j=per[i];
while(l>=&&multiX(getmag(q[l-],p[j]),getmag(q[l-],q[l]))>=){
l--;
}
q[++l]=p[j];
}
return;
}
bool judge(){
for(int i=;i<=l;i++){
int sum=;
for(int j=;j<=n;j++){
if(multiX(getmag(q[i],p[j]),getmag(p[j],q[i%l+]))==)sum++;
}
if(sum<)return ;
}
bool flag=;
for(int i=;i<=l&&!flag;i++){
if(multiX(getmag(q[i-],q[i]),getmag(q[i],q[i%l+]))!=)flag=;
}
return flag;
}
int main(){
int t;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i=;i<=n;i++)scanf("%d%d",&p[i].x,&p[i].y);
graham();
if(judge())puts("YES");
else puts("NO");
}
return ;
}

POJ1228:Grandpa's Estate——题解的更多相关文章

  1. poj1228 Grandpa's Estate

    地址:http://poj.org/problem?id=1228 题目: Grandpa's Estate Time Limit: 1000MS   Memory Limit: 10000K Tot ...

  2. POJ1228 Grandpa's Estate 稳定凸包

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

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

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

  4. POJ1228:Grandpa's Estate(给定一些点,问是否可以确定一个凸包)

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

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

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

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

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

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

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

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

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

  9. 【POJ 1228】Grandpa's Estate 凸包

    找到凸包后暴力枚举边进行$check$,注意凸包是一条线(或者说两条线)的情况要输出$NO$ #include<cmath> #include<cstdio> #include ...

随机推荐

  1. CC3200底板测试-烧写CC3200-LAUNCHXL

    1. 拿到板子,先研究一下几个跳线帽的作用.我在底板上测到VCC_DCDC_3V3和VCC_BRD之间应该有一个跳线帽的,但是在原理上找不到. 2. LED灯的用途,测试的时候,发现这个灯有时候亮,有 ...

  2. Python 列表下标操作

    Python  列表下标操作 引用网址: https://www.jianshu.com/p/a98e935e4d46

  3. 【Extremely Basic Words for Listening】word list

    [Extremely Basic Words for Listening]word list updated continuously recite count: 0 careless exercis ...

  4. 拥抱移动端,jQueryui触控设备兼容插件

    http://touchpunch.furf.com/ ps:要FQ. jQuery UI Touch Punch Touch Event Support for jQuery UI Tested o ...

  5. 【Linux 运维】Centos7初始化网络配置

    设置网络 (1)动态获取一个IP地址 #dhclient        系统自动自动获取一个IP地址#ip addr         查看获取的ip地址(2)查看网关,子网掩码 虚拟机编辑>虚拟 ...

  6. 【第五章】MySQL数据库的安全机制

    MySQL权限表MySQL用户管理MySQL权限管理SSL加密连接

  7. 一:HDFS 用户指导

    1.hdfs的牛逼特性 Hadoop, including HDFS, is well suited for distributed storage and distributed processin ...

  8. Python的实现分类

    目前流行的Python实现包括CPython,Jython,IronPython,Stackless,PyPy,Cython,Shed Skin. CPython Cpython是Python的标准实 ...

  9. Python—列表(一个“打了激素”的数组)

    我们在C语言中会使用数组来将一大堆数据类型一样的数据挨个摆在一起,但是数组有一个基本的要求,就是数据类型必须是一致的,我们知道Python的变量由于没有数据类型,也就是说Python没有数组这一概念, ...

  10. Java学习个人备忘录之内部类

    内部类: 将一个类定义在另一个类的里面,对里面那个类就称为内部类. class Outer { private int num = 3; class Inner //它想访问Outer中的num, 如 ...