就是给一系列点,看这是不是一个稳定凸包

稳定凸包是指一个凸包不能通过加点来使它扩大面积,也就是说每条边最少有三个点

判断的地方写错了,写了两边循环,其实数组s已经排好了序,直接每三个判断就好了

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cassert>
#include<iomanip>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f; struct point{
double x,y;
};
point p[N],s[N];
int n;
double dir(point p1,point p2,point p3)
{
return (p3.x-p1.x)*(p2.y-p1.y)-(p3.y-p1.y)*(p2.x-p1.x);
}
double dis(point p1,point p2)
{
return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
}
bool comp(point p1,point p2)
{
double te=dir(p[],p1,p2);
if(te<)return ;
if(te==&&dis(p[],p1)<dis(p[],p2))return ;
return ;
}
bool graham()
{
int pos;
double minx,miny;
minx=miny=inf;
for(int i=;i<n;i++)
{
if(p[i].y<miny||(p[i].y==miny&&p[i].x<minx))
{
minx=p[i].x;
miny=p[i].y;
pos=i;
}
}
swap(p[],p[pos]);
sort(p+,p+n,comp);
int top=;
p[n]=p[];
s[]=p[],s[]=p[],s[]=p[];
for(int i=;i<=n;i++)
{
while(top>=&&dir(s[top-],s[top],p[i])>)top--;
s[++top]=p[i];
}
/* cout<<endl;
for(int i=0;i<n;i++)
cout<<p[i].x<<" "<<p[i].y<<endl;
cout<<endl;
for(int i=0;i<top;i++)
cout<<s[i].x<<" "<<s[i].y<<endl;*/
for(int i=;i<top-;i++)
{
if(dir(s[i-],s[i],s[i+])!=&&dir(s[i],s[i+],s[i+])!=)
return ;
}
return ;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
int t;
cin>>t;
while(t--){
cin>>n;
for(int i=;i<n;i++)
cin>>p[i].x>>p[i].y;
if(n<)
{
cout<<"NO"<<endl;
continue;
}
if(graham())cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return ;
}
/*
1
4
0 1
0 2
0 3
0 4
*/

poj1228稳定凸包的更多相关文章

  1. POJ1228(稳定凸包问题)

    题目:Grandpa's Estate   题意:输入一个凸包上的点(没有凸包内部的点,要么是凸包顶点,要么是凸包边上的点),判断这个凸包是否稳定.所谓稳 定就是判断能不能在原有凸包上加点,得到一个更 ...

  2. POJ1228 Grandpa's Estate 稳定凸包

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

  3. POJ 1228 - Grandpa's Estate 稳定凸包

    稳定凸包问题 要求每条边上至少有三个点,且对凸包上点数为1,2时要特判 巨坑无比,调了很长时间= = //POJ 1228 //稳定凸包问题,等价于每条边上至少有三个点,但对m = 1(点)和m = ...

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

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

  5. poj 1228 稳定凸包

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

  6. POJ 1228 (稳定凸包问题)

    <题目链接> <转载于  >>> > 首先来了解什么是稳定的凸包.比如有4个点: 这四个点是某个凸包上的部分点,他们连起来后确实还是一个凸包.但是原始的凸包可 ...

  7. poj1228(稳定凸包+特判最后一条边)

    题目链接:https://vjudge.net/problem/POJ-1228 题意:我是真的没看懂题意QAQ...搜了才知道.题目给了n个点,问这n个点确定的凸包是否能通过添加点来变成一个新的凸包 ...

  8. POJ1228+凸包

    见代码. /* 凸包(稳定凸包) 题意:给出一些点,这些点要么是凸包的顶点要么是边上的. 证明每条边上都至少有3个点. */ #include<stdio.h> #include<s ...

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

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

随机推荐

  1. PAT 1096 Consecutive Factors[难]

    1096 Consecutive Factors (20 分) Among all the factors of a positive integer N, there may exist sever ...

  2. PAT 1039 Course List for Student[难]

    1039 Course List for Student (25 分) Zhejiang University has 40000 students and provides 2500 courses ...

  3. ActiveMQ简单入门

    一.创建一个简单的Hello World案例 首先需要导入activemq-all-5.14.5.jar包,写生产端: package com.ietree.mq.helloworld; import ...

  4. Mac下的Mysql无法登陆的问题

    以下是还原root权限和更改root密码的最便捷方法. 1:装mysql workbench .可视化界面直接操作. 2:苹果->系统偏好设置->最下边点mysql 在弹出页面中 关闭my ...

  5. Git-创建和合并分支

    本人拜读了廖雪峰老师关于Git的讲述后整理所得 分支就是科幻电影里面的平行宇宙,当你正在电脑前努力学习Git的时候,另一个你正在另一个平行宇宙里努力学习SVN. 如果两个平行宇宙互不干扰,那对现在的你 ...

  6. Zookeeper那些事

    一. 什么是Zookeeper Zookeeper 是 Google 的 Chubby一个开源的实现,是 Hadoop 的分布式协调服务 它包含一个简单的原语集,分布式应用程序可以基于它实现同步服务, ...

  7. 3.1.7. Cross validation of time series data

    3.1.7. Cross validation of time series data Time series data is characterised by the correlation bet ...

  8. 101. Symmetric Tree(判断二叉树是否对称)

      Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For ...

  9. hdu6127 Hard challenge

    地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6127 题目: Hard challenge Time Limit: 4000/2000 MS ...

  10. windows安装VisualSVN Server