codeforces 113 166B 凸包 计算几何

判断一个多边形能否放进凸包中

对所有点再做一次凸包,把重点和共线点都加进凸包集合中

如果图暴集合中有某个点是多边形的点就输出no

else yes

View Code
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef __int64 lld;
const double eps = 1e-8;
const double pi = acos(-1.0);
struct Point {
lld x, y;
int id;
bool operator == (const Point& t) const {
return x==t.x && y==t.y;
}
}GP,p[1000010];
inline lld Cross(Point a, Point b, Point c) { // 叉积
return (b.x-a.x)*(c.y-a.y) - (c.x-a.x)*(b.y-a.y);
}
bool cmpyx(Point a, Point b) {
if ( a.y != b.y )
return a.y < b.y;
return a.x < b.x;
}
void Grahamxy(Point *p, int &n) { // 水平序(住:两倍空间)
if ( n < 3 )
return;
int i, m=0, top=1;
// sort(p, p+n, cmpyx);
for (i=n; i < 2*n-1; i++)
p[i] = p[2*n-2-i];
for (i=2; i < 2*n-1; i++) {
while ( top > m && Cross(p[top], p[i], p[top-1]) < 0 )
top--;
p[++top] = p[i];
if ( i == n-1 ) m = top;
}
n = top;
}
int main(){
int n,m,i,j;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%I64d%I64d",&p[i].x,&p[i].y); p[i].id=1;
scanf("%d",&m);
for(i=0;i<m;i++)
scanf("%I64d%I64d",&p[i+n].x,&p[i+n].y);p[i+n].id=-1;
n=n+m;
sort(p,p+n,cmpyx);
Grahamxy(p,n);
for(i=1;i<=n;i++) {
if(p[i].id<0){
printf("NO\n");
return 0;
}
}
printf("YES\n");
return 0;
}



posted @ 2012-03-24 19:14  Because Of You  Views(372)  Comments(0Edit  收藏  举报