Grandpa's Estate - POJ 1228(稳定凸包)
2015-10-25 11:45
309 查看
刚开始看这个题目不知道是什么东东,后面看了大神的题解才知道是稳定凸包问题,什么是稳定凸包呢?所谓稳定就是判断能不能在原有凸包上加点,得到一个更大的凸包,并且这个凸包包含原有凸包上的所有点。知道了这个东西就简单了,直接求出来凸包后,然后判断每条边上的点是否超过三点就行了。
代码如下:
============================================================================================================================
代码如下:
============================================================================================================================
#include<stdio.h> #include<string.h> #include<algorithm> #include<math.h> using namespace std; const double EPS = 1e-16; const int MAXN = 1007; const int oo = 1e9+7; int sta[MAXN], top; struct point { double x, y; point(double x=0, double y=0):x(x), y(y){} point operator - (const point &t)const{ return point(x-t.x, y-t.y); } double operator *(const point &t)const{ return x*t.x + y*t.y; } double operator ^(const point &t)const{ return x*t.y - y*t.x; } }p[MAXN]; int Sign(double t) { if(t > EPS)return 1; if(fabs(t) < EPS)return 0; return -1; } double Dist(point a, point b) { return sqrt((a-b)*(a-b)); } bool cmp(point a, point b) { int t = Sign((a-p[0])^(b-p[0])); if(t == 0) return Dist(a, p[0]) < Dist(b, p[0]); return t > 0; } void Graham(int N) { int k=0; for(int i=0; i<N; i++) { if(p[k].y>p[i].y || (Sign(p[k].y-p[i].y)==0 && p[k].x > p[i].x)) k = i; } swap(p[0], p[k]); sort(p+1, p+N, cmp); sta[0]=0, sta[1]=1, top=1; if(N < 2) { top = N-1; return ; } for(int i=2; i<N; i++) { while(top>0 && Sign((p[i]-p[sta[top]])^(p[sta[top-1]]-p[sta[top]])) <= 0) top--; sta[++top] = i; } } int main() { int T, N, i, j; scanf("%d", &T); while(T--) { scanf("%d", &N); for(i=0; i<N; i++) scanf("%lf%lf", &p[i].x, &p[i].y); Graham(N); sta[++top] = sta[0]; for(i=0; i<top; i++) { int s=sta[i], e=sta[i+1]; for(j=0; j<N; j++) { if(j==s || j==e) continue; if(Sign( (p[s]-p[e])^(p[j]-p[e]) ) == 0) break; } if(j == N) break; } if(i < top || top < 3) printf("NO\n"); else printf("YES\n"); } return 0; }
相关文章推荐
- 详解c++指针的指针和指针的引用
- maven2.2 + tomcat6.0 + Eclipse3.4 实现的自动部署和debug
- iOS9 HTTP 不能正常使用的解决办法
- Android ProgressBar
- TCP/IP 基本了解
- (五)redis持久化
- 【RHCE学习笔记】RHEL7下ISCSI存储的配置过程
- HDU1281(二分图最大匹配,棋盘建图,找关键点)
- 按后退键直接回到系统Home界面
- Eclipse使用Space键替换Tab键不生效的解决方案
- Sort Color
- skyeye安装+arm-elf-gdb安装+模拟s3c44b0x+运行ucos4skyeye
- “用户需求”之“切入需求”
- C和C++语言中基本的数据类型
- UML——类图
- Testing the CATCHER Uva231 最长递减子序列
- 自定义ViewGroup
- [洛谷1113]杂务
- float属性
- SQL的四种连接-左外连接、右外连接、内连接、全连接