Poj1228 Grandpa's Estate
来源:互联网 发布:网络证券交易平台 编辑:程序博客网 时间:2024/06/02 17:33
给出了一些凸包上的点,问该凸包是否为稳定凸包。
稳定凸包即指在不删掉当前凸包上的点的情况下,无法通过加点来得到更大的凸包。这样的凸包每条边上除两端点外都一定还有点。
求出凸包顶点,判断凸包每条边上是否还有点即可。
既然那么多人都写Graham,那我就写写分治来愉悦一下吧。
#include<cstdio>#include<cstring>#include<cstdlib>#include<iostream>#include<cmath>using namespace std;const int maxn = 1005;#define EPS 1e-6#define INF 1e9struct point { double x,y; point(){} point(double _x,double _y):x(_x),y(_y){} point operator - (const point &a) {return point(x-a.x,y-a.y);} bool operator != (const point &a) {return x!=a.x || y!=a.y;} bool operator == (const point &a) {return x==a.x && y==a.y;}};double multi(point a,point b) {return a.x*b.y - a.y*b.x;}double dis(point a,point b) {point c=a-b;return sqrt(1.0*c.x*c.x+1.0*c.y*c.y);}bool cmp(point a,point b) {return a.x < b.x || (a.x==b.x && a.y < b.y);}point P[maxn],hull[maxn];int N,cnt=0;double s[maxn];void quickhull(int L,int R,point a,point b) { int x = L,i=L-1,j=R+1; for(int k = L; k <= R; k++) if( s[k]-s[x] > EPS || ( fabs(s[x]-s[k])<EPS && cmp(P[x],P[k]))) x=k; point y = P[x]; for(int k = L; k <= R; k++) { s[++i] = multi(a-P[k],y-P[k]); if( s[i] > EPS) swap(P[i],P[k]); else i--; } for(int k = R; k >= L; k--) { s[--j] = multi(y-P[k],b-P[k]); if( s[j] > EPS) swap(P[j],P[k]); else j++; } if( L <= i ) quickhull(L,i,a,y); hull[++cnt] = y; if( j <= R ) quickhull(j,R,y,b);}bool judge(point a,point b,point k) { return fabs(multi(k-a,b-a)) < EPS;}int main() { int T; for(scanf("%d",&T);T;T--) { scanf("%d",&N); memset(s,0,sizeof s); P[0] = point(INF,INF); int x = 0; for(int i = 1; i <= N; i++) { scanf("%lf%lf",&P[i].x,&P[i].y); if( cmp(P[i],P[x]) ) x=i; } if(N< 5) {puts("NO"); continue;} swap(P[1],P[x]); cnt=0; hull[++cnt] = P[1]; quickhull(2,N,P[1],P[1]); hull[++cnt] = P[1]; bool fg = 1; for(int i = 2; i <= cnt; i++) { point a = hull[i-1]; point b = hull[i]; bool found=0; for(int j = 1; j <= N; j++){ if(P[j] == a || P[j] == b) continue; if(judge(a,b,P[j])) {found=1;break;} } if( !found ){ fg = 0; break;} } puts( fg ? "YES" : "NO"); }}
0 0
- POJ1228 Grandpa's Estate
- poj1228 - Grandpa's Estate
- POJ1228--Grandpa's Estate
- POJ1228-Grandpa's Estate
- Poj1228 Grandpa's Estate
- POJ1228 Grandpa's Estate 还是凸包
- POJ1228-Grandpa's Estate(凸包)
- poj1228 Grandpa's Estate 凸包
- poj1228 Grandpa's Estate(凸包)
- [POJ1228]Grandpa's Estate(凸包)
- 【稳定凸包】poj1228 Grandpa's Estate
- Grandpa's Estate(poj1228稳定的凸包)
- poj1228 Grandpa's Estate【凸包稳定性判断】
- POJ1228 Grandpa's Estate 计算几何 唯一凸包的确定条件
- POJ1228——Grandpa's Estate(计算几何,凸包)
- poj1228-Grandpa's Estate 带边上节点的凸包(稳定凸包)问题
- pku1228 Grandpa's Estate
- poj Grandpa's Estate
- 天池大数据比赛,菜鸟仓库比赛,御膳房操作
- 经典计算机视觉论文笔记——《Robust Real-Time Face Detection》
- Read Phone Number
- 同时加载执行多个js函数addLoadEvent()
- css部分细节(持续更新)
- Poj1228 Grandpa's Estate
- 鸟哥Java学习之构造函数、this、static关键字-面向对象
- 本地代码托管到github
- HttpUtils&Pull解析XML
- Android中attrs.xml文件的使用详解
- WebView入门
- 鸟哥Java学习之单例设计、继承-面向对象
- Linux内核栈与用户栈分析
- poj 3084(最小割)