Quantcast
Channel: CSDN博客推荐文章
Viewing all articles
Browse latest Browse all 35570

11072 - Points

$
0
0
#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;
}

作者:u010395983 发表于2013-6-6 23:28:38 原文链接
阅读:114 评论:0 查看评论

Viewing all articles
Browse latest Browse all 35570

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>