POJ1228+凸包
见代码。
/*
凸包(稳定凸包)
题意:给出一些点,这些点要么是凸包的顶点要么是边上的。
证明每条边上都至少有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+凸包的更多相关文章
- POJ1228 Grandpa's Estate 稳定凸包
POJ1228 转自http://www.cnblogs.com/xdruid/archive/2012/06/20/2555536.html 这道题算是很好的一道凸包的题吧,做完后会加深对凸包的 ...
- poj1228(稳定凸包+特判最后一条边)
题目链接:https://vjudge.net/problem/POJ-1228 题意:我是真的没看懂题意QAQ...搜了才知道.题目给了n个点,问这n个点确定的凸包是否能通过添加点来变成一个新的凸包 ...
- POJ1228(稳定凸包问题)
题目:Grandpa's Estate 题意:输入一个凸包上的点(没有凸包内部的点,要么是凸包顶点,要么是凸包边上的点),判断这个凸包是否稳定.所谓稳 定就是判断能不能在原有凸包上加点,得到一个更 ...
- poj1228稳定凸包
就是给一系列点,看这是不是一个稳定凸包 稳定凸包是指一个凸包不能通过加点来使它扩大面积,也就是说每条边最少有三个点 判断的地方写错了,写了两边循环,其实数组s已经排好了序,直接每三个判断就好了 #in ...
- POJ1228:Grandpa's Estate(给定一些点,问是否可以确定一个凸包)
Being the only living descendant of his grandfather, Kamran the Believer inherited all of the grandp ...
- 【kuangbin专题】计算几何_凸包
1.poj1113 Wall 题目:http://poj.org/problem?id=1113 题意:用一条线把若干个点包起来,并且线距离任何一个点的距离都不小于r.求这条线的最小距离是多少? 分析 ...
- [poj1113][Wall] (水平序+graham算法 求凸包)
Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall ...
- ZOJ 3871 Convex Hull(计算几何、凸包)
题意:给n个点,|x[i]|,|y[i]| <= 1e9.求在所有情况下的子集下(子集点数>=3),凸包的面积和. 这题主要有几个方面,一个是凸包的面积,可以直接用线段的有向面积和求得,这 ...
- UVALive 2453 Wall (凸包)
题意:给你一个多边形的城堡(多个点),使用最短周长的城墙将这个城堡围起来并保证城墙的每个点到城堡上的每个点的距离都不小于l 题解:因为两点间的直线一定比折线短,所以这样做 先使用所有点求得一个凸包,接 ...
随机推荐
- JAVA实现上传下载共享文件
1.上传下载共享文件需要用到jcifs,先下载相关JAR包(开源项目的源码,demo,文挡.API应有尽有) https://jcifs.samba.org/src/
- 20141015--for语句1
for 语句 break (跳出循环体) 100节楼梯,第1-49节分数等于节数,50以后(包括50)每节10分,
- 深入理解JavaScript中的this关键字
1. 一般用处 2. this.x 与 apply().call() 3. 无意义(诡异)的this用处 4. 事件监听函数中的this 5. 总结 在JavaScript中this变量是一个令人难以 ...
- java新手笔记32 jdk5新特性
1.for package com.yfs.javase; import java.awt.Color; import java.util.Calendar; import java.util.Has ...
- [easyui] datebox源码阅读. 批注
jquery.datebox.js 文件. (function($){ /** * create date box */ function createBox(target){ var state = ...
- 最新模仿ios版微信应用源码
这个是刚刚从那个IOS教程网http://ios.662p.com分享来的,也是一个很不错的应用源码,仿微信基本功能.基于XMPP服务器的即时通信以及交友客户端. ----第一期代码的功能如下---- ...
- python练习 根据日志中的ip和url排序
#!/usr/bin/env python #coding:utf-8 def open_file(file_name): res={} with open(file_name) as f: for ...
- iis7伪静态
http://jingyan.baidu.com/article/67508eb4ff92c69cca1ce49a.html
- jQuery ui 中文日历
jQuery ui 中文日历 <link href="css/jquery-ui-1.10.4.custom.min.css" rel="stylesheet&qu ...
- LM算法
最小二乘法的概念 最小二乘法的目标:求误差的最小平方和,对应有两种:线性和非线性. 线性最小二乘的解是closed-form即x=(A^T A)^{-1}A^Tb, 而非线性最小二乘没有closed- ...