poj1228稳定凸包
就是给一系列点,看这是不是一个稳定凸包
稳定凸包是指一个凸包不能通过加点来使它扩大面积,也就是说每条边最少有三个点
判断的地方写错了,写了两边循环,其实数组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稳定凸包的更多相关文章
- POJ1228(稳定凸包问题)
题目:Grandpa's Estate 题意:输入一个凸包上的点(没有凸包内部的点,要么是凸包顶点,要么是凸包边上的点),判断这个凸包是否稳定.所谓稳 定就是判断能不能在原有凸包上加点,得到一个更 ...
- POJ1228 Grandpa's Estate 稳定凸包
POJ1228 转自http://www.cnblogs.com/xdruid/archive/2012/06/20/2555536.html 这道题算是很好的一道凸包的题吧,做完后会加深对凸包的 ...
- POJ 1228 - Grandpa's Estate 稳定凸包
稳定凸包问题 要求每条边上至少有三个点,且对凸包上点数为1,2时要特判 巨坑无比,调了很长时间= = //POJ 1228 //稳定凸包问题,等价于每条边上至少有三个点,但对m = 1(点)和m = ...
- Grandpa's Estate - POJ 1228(稳定凸包)
刚开始看这个题目不知道是什么东东,后面看了大神的题解才知道是稳定凸包问题,什么是稳定凸包呢?所谓稳定就是判断能不能在原有凸包上加点,得到一个更大的凸包,并且这个凸包包含原有凸包上的所有点.知道了这个东 ...
- poj 1228 稳定凸包
Grandpa's Estate Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12337 Accepted: 3451 ...
- POJ 1228 (稳定凸包问题)
<题目链接> <转载于 >>> > 首先来了解什么是稳定的凸包.比如有4个点: 这四个点是某个凸包上的部分点,他们连起来后确实还是一个凸包.但是原始的凸包可 ...
- poj1228(稳定凸包+特判最后一条边)
题目链接:https://vjudge.net/problem/POJ-1228 题意:我是真的没看懂题意QAQ...搜了才知道.题目给了n个点,问这n个点确定的凸包是否能通过添加点来变成一个新的凸包 ...
- POJ1228+凸包
见代码. /* 凸包(稳定凸包) 题意:给出一些点,这些点要么是凸包的顶点要么是边上的. 证明每条边上都至少有3个点. */ #include<stdio.h> #include<s ...
- POJ 1228 Grandpa's Estate --深入理解凸包
题意: 判断凸包是否稳定. 解法: 稳定凸包每条边上至少有三个点. 这题就在于求凸包的细节了,求凸包有两种算法: 1.基于水平序的Andrew算法 2.基于极角序的Graham算法 两种算法都有一个类 ...
随机推荐
- PAT 1051 Pop Sequence[栈][难]
1051 Pop Sequence (25 分) Given a stack which can keep M numbers at most. Push N numbers in the order ...
- EventFiringWebDriver网页事件监听(二)
public class SeleniumDemo { /** * @param args */ public static void main(String[] args) { WebDriver ...
- django 【认证】
一.验证 1.views.py from django.contrib.auth.decorators import login_required from django.contrib.auth i ...
- undefined reference to _imp__xmlFree
Re: [xml] MSYS and MINGW: undefined reference to _imp__xmlFree From: Mike Peat <mpeat unicorninte ...
- (C++) Assertion failed: !"Bad error code", file VMem.c, line 715
(C++) Assertion failed: !"Bad error code", file VMem.c, line 715 Misc error. myInterface F ...
- vmware12 安装linux centos6
内核选 2.6 中文安装选 基本系统 -> 基本, 兼 ...
- C# 将 HTML 转换为图片或 PDF
首先是把 HTML 转换为图片. public partial class Form1 : Form { public Form1() { InitializeComponent(); } WebBr ...
- tensorflow(二)----线程队列与io操作
一.队列和线程 1.队列: 1).tf.FIFOQueue(capacity, dtypes, name='fifo_queue') 创建一个以先进先出的顺序对元素进行排队的队列 参数: capaci ...
- HDU 3081 Marriage Match II (二分+并查集+最大流)
题意:N个boy和N个girl,每个女孩可以和与自己交友集合中的男生配对子;如果两个女孩是朋友,则她们可以和对方交友集合中的男生配对子;如果女生a和女生b是朋友,b和c是朋友,则a和c也是朋友.每一轮 ...
- spray-json
spray-json是一个轻量级的,简介的和高效的使用Scala实现的json 它拥有以下特征: 一个简单不可变的模型的json语言元素 一个高效的json解析器 可选择既紧凑又漂亮的json到str ...