Grandpa's Estate
来源:互联网 发布:乐其网络骗局 编辑:程序博客网 时间:2024/06/05 19:09
Grandpa's Estate
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 13640 Accepted: 3816
Description
Being the only living descendant of his grandfather, Kamran the Believer inherited all of the grandpa's belongings. The most valuable one was a piece of convex polygon shaped farm in the grandpa's birth village. The farm was originally separated from the neighboring farms by a thick rope hooked to some spikes (big nails) placed on the boundary of the polygon. But, when Kamran went to visit his farm, he noticed that the rope and some spikes are missing. Your task is to write a program to help Kamran decide whether the boundary of his farm can be exactly determined only by the remaining spikes.
Input
The first line of the input file contains a single integer t (1 <= t <= 10), the number of test cases, followed by the input data for each test case. The first line of each test case contains an integer n (1 <= n <= 1000) which is the number of remaining spikes. Next, there are n lines, one line per spike, each containing a pair of integers which are x and y coordinates of the spike.
Output
There should be one output line per test case containing YES or NO depending on whether the boundary of the farm can be uniquely determined from the input.
Sample Input
16 0 01 23 42 02 4 5 0
Sample Output
NO
题意:给出一些点,判断凸包是否唯一
思路:判断凸包上的点中间是否有点,都有的话就稳定
#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<cmath>#include<queue>#include<stack>#include<vector>#include<cstring>#include<string>#include<algorithm>using namespace std;#define ll long long#define ms(a,b)memset(a,b,sizeof(a))#define eps 1e-10#define inf 1e8double a[4][4] = { {0,0,0,0},{0,-1,0,0},{0,0,0,-1},{0,-1,0,-1} } ;int n;double add(double a,double b){ if(abs(a+b)<eps*(abs(a)+abs(b))) return 0; return a+b;}struct P{ double x,y; double val; double len; P(){} P(double x,double y): x(x),y(y){} P operator + (P p) { return P(add(x,p.x),add(y,p.y)); } P operator - (P p) { return P(add(x,-p.x),add(y,-p.y)); } P operator *(double d) { return P(x*d,y*d); } double dot (P p) { return add(x*p.x,y*p.y); } double det(P p) { return add(x*p.y,-y*p.x); }}p[2000];bool on_seg(P p1,P p2,P q){ return (p1-q).det(p2-q)==0&&(p1-q).dot(p2-q)<0;}P intersection(P p1,P p2,P q1,P q2){ return p1+(p2-p1)*((q2-q1).det(q1-p1)/(q2-q1).det(p2-p1));}double ConvexPolygonArea(vector<P> p) { double area = 0; for(int i = 1; i+1 < p.size(); i++) area+=(p[i]-p[0]).det(p[i + 1]-p[0]); return area / 2;}bool cmp_x(const P& p,const P & q){ if(p.x!=q.x) return p.x<q.x; return p.y<q.y;}vector<P> convex_hull(P *ps,int n){ sort(ps,ps+n,cmp_x); int k=0; vector<P> qs(n*2); if(n==0) return qs; for(int i=0;i<n;i++) { while(k>1&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0) k--; qs[k++]=ps[i]; } for(int i=n-2,t=k;i>=0;i--) { while(k>t&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0) k--; qs[k++]=ps[i]; } qs.resize(k-1); return qs;}int main(){ int n,t; cin>>t; while(t--) { scanf("%d",&n); for(int i=0;i<n;i++) scanf("%lf%lf",&p[i].x,&p[i].y); vector<P> q=convex_hull(p,n); int q_size=q.size(); if(q_size<3) { printf("NO\n"); continue; } bool flag=1; for(int i=0;i<q_size;i++) { bool ok=false; for(int j=0;j<n;j++) { if(on_seg(q[i],q[(i+1)%q_size],p[j])) ok=true; } if(!ok) flag=0; } if(flag) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0 ;}
阅读全文
0 0
- POJ1228 Grandpa's Estate
- pku1228 Grandpa's Estate
- poj1228 - Grandpa's Estate
- POJ1228--Grandpa's Estate
- poj Grandpa's Estate
- POJ1228-Grandpa's Estate
- Grandpa's Estate
- Poj1228 Grandpa's Estate
- Grandpa's Estate
- Grandpa's Estate POJ
- 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
- 【转】JVM调优总结(十二)-参考资料
- 同时安装vs2013与vs2101无法打开包括文件:“SDKDDKVer.h
- Leetcode 410. Split Array Largest Sum
- 时光机穿梭
- 2.swap-two-nodes-in-linked-list(交换链表中的两个结点)
- Grandpa's Estate
- React 入门实例教程
- 机器学习之numpy和matplotlib学习(三)
- Windows下的Socket网络编程小实战
- 原子变量和CAS算法简单介绍
- 个人小作品之迷你音乐播放器(移动端)
- QTableWidget如何实现换行功能?
- 系统分析与设计学习笔记(六)包图
- 版本回退