11072 - Points
来源:互联网 发布:java wait join区别 编辑:程序博客网 时间:2024/06/05 11:59
Points
In this problem you will be given a set of points in the Euclidian plane. The number of points in the set will never exceed100000.The coordinates of these points will be integer coordinates and will have an absolute value smaller than10000. There will be no identical points in the first set. Then you will be given a second set of points. For each point in the second set you will have to determinewhether it lies in a triangle spanned by three points in the first set. A point lying on the edge of a triangle is considered to be "inside" the triangle.
In the following example the points p1,p2,p3,p4 belong to the first set. The pointsr and s belong to the second set. The point r isn't contained in any triangle spanned by three points of the first set. The points is contained in two triangles. For example, the triangle spanned by p2,p3,p4.
Input
You will be given several testcases. A testcases consists of the number of pointsp, 3 ≤ p ≤ 100000 in the first set. It is followed by p pairs of numbers, each describing a point of the first set, the first number of a pair denoting thex-coordinate of the point, the second they-coordinate. Each pair is on a seperate line. There may be colinear points in the first set. The next number in the input gives you the number of pointsr in the second set. It is followed by r pairs of numbers, each describing a point, each on a separate line. The first number of a pair being thex-coordinate, the second number being the y-coordinate of the point. All coordinates in the inputwill be integer coordinates.Output
For each point in the second set, output if the point lies in a triangle spanned by three points of the first set. If the point lies inside a triangle outputinside otherwise output outside.Sample input
40 04 40 44 062 24 41 10 20 1010 0
Sample output
insideinsideinsideinsideoutsideoutside
#include<iostream>#include<algorithm>using namespace std;struct point{double x;double y;point(double x=0, double y=0):x(x),y(y){}}p[100005],a,ch[100005];typedef point vector;vector operator-(point a, point b){return vector(a.x-b.x,a.y-b.y);}double cross(vector a, vector b){return a.x*b.y-a.y*b.x;}bool operator<(const point& a,const point& b){return a.x<b.x||(a.x==b.x&&a.y<b.y);} int convexhull(point *p,int n,point *ch){sort(p,p+n);int m=0;for(int i=0;i<n;i++){while(m>1&&cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0)m--;ch[m++]=p[i];}int k=m;for(int i=n-2;i>=0;i--){while(m>k&&cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0)m--;ch[m++]=p[i];}if(n>1) m--;return m;}int main(){int n,t;while(cin>>n){for(int i=0;i<n;i++)cin>>p[i].x>>p[i].y;int m=convexhull(p,n,ch);cin>>t;while(t--){cin>>a.x>>a.y;for(int i=0;i<m;i++)if(cross(ch[i+1]-ch[i],a-ch[i])<0) goto out;cout<<"inside"<<endl;continue;out:cout<<"outside"<<endl;}}return 0;}
- 11072 - Points
- Points
- points
- points
- uva 11072 - Points(凸包)
- Hay Points
- Hay Points
- small points
- pku3512Incidental Points
- Notes, Points
- 仪仗队(points)
- Points Within
- some points
- Points Within
- multiple points
- Spark Points
- Cocircular Points
- (beginer) 凸包+点在多边形内 UVA 11072 Points
- jdk配置
- 代码安全系列(2) - Race Condition
- ExpandableListView吐槽系列(一)
- ASP.NET中的URL编码解码
- 题目1055:数组逆置
- 11072 - Points
- 朴素贝叶斯算法
- 分析oracle的sequence序列的跳号现象
- linux platform 设备与驱动的匹配
- 安卓开发之地图加载
- Linux oops
- 将openwrt移植到belkin F5D8235V2
- 《xUnit Test Patterns》学习笔记1 - Test Smell
- URL编码处理