POJ 1228 稳定凸包问题
来源:互联网 发布:数据结构与算法的关系 编辑:程序博客网 时间:2024/06/16 05:20
题意:给出一些凸包上的点 这些点均是凸包上的点 判断该凸包是否为稳定凸包 即是否每条边上是否至少有三个点 改下凸包的模板即可#include <iostream>#include "stdio.h"#include "stdlib.h"#include "string.h"#include "math.h"#include "algorithm"#include <queue>using namespace std;#define modulo 1000000007const double eps=1e-8;int n,top;double ansx,ansy;struct ed { double x,y;}point[1010],sta[1010];double mult(double x1,double y1,double x2,double y2,double x3,double y3){ return (x1-x3)*(y2-y3)-(y1-y3)*(x2-x3);}int sgn(double x){ if(fabs(x)<eps) return 0; if(x<0) return -1; else return 1;}double dis(ed a,ed b){ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}int cmp(const void *a,const void *b){ ed c=*(ed *)a; ed d=*(ed *)b; double k=mult(c.x,c.y,d.x,d.y,point[0].x,point[0].y); if(k<0||(!k&&dis(c,point[0])>dis(d,point[0]))) return 1; else return -1;}void convex(){ for(int i=1;i<n;i++) { ed temp; if(point[i].y<point[0].y||(point[i].y==point[0].y&&point[i].x<point[0].x)){ temp=point[i]; point[i]=point[0]; point[0]=temp; } } qsort(point+1,n-1,sizeof(point[0]),cmp); sta[0]=point[0];sta[1]=point[1]; top=1; for(int i=2;i<n;i++) { while(top>=1&&mult(sta[top].x,sta[top].y,point[i].x,point[i].y,sta[top-1].x,sta[top-1].y)<0) top--; top++; sta[top]=point[i]; }}bool judge(){ for(int i=1;i<top;i++) if(mult(sta[i].x,sta[i].y,sta[i+1].x,sta[i+1].y,sta[i-1].x,sta[i-1].y)!=0&&mult(sta[i+1].x,sta[i+1].y,sta[i+2].x,sta[i+2].y,sta[i].x,sta[i].y)!=0) return false; return true;}int main(){ int t; scanf("%d",&t); while(t--) { scanf("%d",&n); for(int i=0;i<n;i++) scanf("%lf%lf",&point[i].x,&point[i].y); if(n<6) printf("NO\n"); else { convex(); if(judge()) printf("YES\n"); else printf("NO\n"); } } return 0;}
0 0
- POJ 1228 稳定凸包问题
- POJ 1228 (稳定凸包问题)
- POJ 1228(稳定凸包)
- POJ 1228 稳定凸包
- POJ-1228(稳定凸包)
- poj 1228 求一个稳定凸包
- POJ 1873 & 1228 凸包和稳定凸包
- POJ1228(稳定凸包问题)
- POJ1228(稳定凸包问题)
- POJ 1228 Grandpa's Estate【稳定凸包判断】
- poj 1228 Grandpa's Estate[稳定凸包]
- POJ 1228 Grandpa's Estate (稳定凸包)
- POJ 1228 Grandpa's Estate(判断是否稳定凸包)
- POJ 1228:Grandpa's Estate (稳定凸包)
- POJ 1228 Grandpa's Estate(稳定凸包)
- POJ 1228 Grandpa's Estate(凸包应用:稳定凸包)
- POJ 1228 Grandpa's Estate(凸包应用:稳定凸包)
- POJ 1228 Grandpa's Estate (稳定凸包的判定)
- [设计模式]-UML类图的各符号含义
- python 决策树学习
- Andoird的两种应用程序界面构建方式
- 周赛HDU超市服务
- uva 1471 Defense Lines
- POJ 1228 稳定凸包问题
- Centos6.5 hadoop新增datanode
- 算法导论 10.2-6 带哨兵的双向链表合并两个不相交的集合
- startActivityForResult与startActivity
- 华为OJ(尼科彻斯定理)
- Lucas定理(C(n,m)mod p)
- Python初学教程
- Android-使用ListView把SQLite中的数据显示至屏幕
- LeetCode 题解(173): Pow(x, n)