见代码。

 /*
凸包(稳定凸包)
题意:给出一些点,这些点要么是凸包的顶点要么是边上的。
证明每条边上都至少有3个点。
*/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<math.h>
using namespace std;
typedef long long int64;
//typedef __int64 int64;
typedef pair<int64,int64> PII;
#define MP(a,b) make_pair((a),(b))
const int maxn = ;
const int inf = 0x7fffffff;
const double pi=acos(-1.0);
const double eps = 1e-; struct Point {
double x,y;
bool operator < ( const Point p ) const {
return y<p.y||(y==p.y&&x<p.x);
}
}res[ maxn ],pnt[ maxn ];
bool flag[ maxn ][ maxn ];//f[i][j]:点ij之间是否还有点
bool ok[ maxn ];//ok[i]:i是否是凸包的顶点 double xmult( Point sp,Point ep,Point op ){
return (sp.x-op.x)*(ep.y-op.y)-(sp.y-op.y)*(ep.x-op.x);
} double dis2( Point a,Point b ){
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
} double dis( Point a,Point b ){
return sqrt( dis2(a,b) );
} bool PointOnLine( Point a,Point L,Point R ){
return ( fabs(xmult( a,L,R ))<eps )&&( (a.x-L.x)*(a.x-R.x)<eps )&&( (a.y-L.y)*(a.y-R.y)<eps );
} int Garham( int n ){
int top = ;
sort( pnt,pnt+n );
if( n== ) return ;
else res[ ] = pnt[ ];
if( n== ) return ;
else res[ ] = pnt[ ];
if( n== ) return ;
else res[ ] = pnt[ ];
for( int i=;i<n;i++ ){
while( top>&&xmult( res[top],res[top-],pnt[i] )>= )
top--;
res[ ++top ] = pnt[ i ];
}
int tmp = top;
res[ ++top ] = pnt[ n- ];
for( int i=n-;i>=;i-- ){
while( top!=tmp&&xmult( res[top],res[top-],pnt[i] )>= )
top--;
res[ ++top ] = pnt[ i ];
}
return top;
} int main(){
int T;
scanf("%d",&T);
while( T-- ){
int n;
scanf("%d",&n);
for( int i=;i<n;i++ )
scanf("%lf%lf",&pnt[i].x,&pnt[i].y);
if( n<= ){
puts("NO");
continue;
}//至少要6个点
int cnt = Garham( n );
memset( ok,false,sizeof( ok ) );
memset( flag,false,sizeof( flag ) );
for( int i=;i<n;i++ ){
for( int j=;j<cnt;j++ ){
if( pnt[i].x==res[j].x&&pnt[i].y==res[j].y ){
ok[ i ] = true;
break;
}
}
}
for( int i=;i<n;i++ ){
if( !ok[i] ){
for( int j=;j<cnt;j++ ){
if( PointOnLine( pnt[i],res[j],res[(j+)%cnt]) ){
flag[ j ][ (j+)%cnt ] = true;
}
}
}
}
bool ans = true;
for( int i=;i<cnt;i++ ){
if( flag[ i ][ (i+)%cnt ]==false ){
ans = false;
break;
}
}
if( ans ) printf("YES\n");
else puts("NO");
}
return ;
}

POJ1228+凸包的更多相关文章

  1. POJ1228 Grandpa's Estate 稳定凸包

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

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

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

  3. POJ1228(稳定凸包问题)

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

  4. poj1228稳定凸包

    就是给一系列点,看这是不是一个稳定凸包 稳定凸包是指一个凸包不能通过加点来使它扩大面积,也就是说每条边最少有三个点 判断的地方写错了,写了两边循环,其实数组s已经排好了序,直接每三个判断就好了 #in ...

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

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

  6. 【kuangbin专题】计算几何_凸包

    1.poj1113 Wall 题目:http://poj.org/problem?id=1113 题意:用一条线把若干个点包起来,并且线距离任何一个点的距离都不小于r.求这条线的最小距离是多少? 分析 ...

  7. [poj1113][Wall] (水平序+graham算法 求凸包)

    Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall ...

  8. ZOJ 3871 Convex Hull(计算几何、凸包)

    题意:给n个点,|x[i]|,|y[i]| <= 1e9.求在所有情况下的子集下(子集点数>=3),凸包的面积和. 这题主要有几个方面,一个是凸包的面积,可以直接用线段的有向面积和求得,这 ...

  9. UVALive 2453 Wall (凸包)

    题意:给你一个多边形的城堡(多个点),使用最短周长的城墙将这个城堡围起来并保证城墙的每个点到城堡上的每个点的距离都不小于l 题解:因为两点间的直线一定比折线短,所以这样做 先使用所有点求得一个凸包,接 ...

随机推荐

  1. Learn Python The Hard Way学习笔记001

    今天搜索了一下raw_input() 和 input()的区别,引用下原文部分内容 两个函数均能接收 字符串 ,但 raw_input() 直接读取控制台的输入(任何类型的输入它都可以接收).而对于 ...

  2. Android 开机自启动应用

    Android启动时,会发出一个系统广播 ACTION_BOOT_COMPLETED,它的字符串常量表示为 “android.intent.action.BOOT_COMPLETED” 开机自启动程序 ...

  3. Tomcat上配置连接池{ connect error=Name [jdbc/OracleDB] is not bound in this Context. Unable to find [jdbc]}

    . 在学习期间,从未实践过在tomcat上配置连接池,今天终于实现一次,在tomcat玩了一把,不知道你是否现在有和我一样的困境.废话少说直接上代码   java  public static Con ...

  4. maven入门程序(二)

    这里就使用myeclipse简单创建一个实例程序. 一.创建项目 在myeclipse中创建项目选Maven Project,然后直接下一步用默认的项目空间.在archetype中选择quicksta ...

  5. 输入与enter

    #include<iostream> using namespace std; int main() { char a,b,c; while(scanf("%c%c%c" ...

  6. linux命令之vim使用-(转)vim的保存文件和退出命令

    博客地址: http://blog.sina.com.cn/s/blog_5e357d2d0100zmth.html

  7. NSS_02 日志配置

    采用log4net,使用系统推荐的最新版本:log4net-1.2.11-bin-newkey.zip(网址:http://logging.apache.org/log4net/download_lo ...

  8. 【转】【C#】无边框窗体移动的三种方法

    1. 重写WndProc protected override void WndProc(ref Message m) { const int WM_NCHITTEST = 0x84; const i ...

  9. jsp日期控件My97DatePicker的使用

    My97DatePicker是一款非常灵活好用的日期控件.使用非常简单. 1.下载My97DatePicker组件包 2.将My97DatePicker包放在项目WebContent目录下 3.在页面 ...

  10. install ruby and ruby gem

    sudo apt-get install ruby #find an folder and: git clone https://github.com/rubygems/rubygems.git cd ...