标签:
给你一个
首先我们求出这个凸包(听别人说这个凸包已经逆时针给出的了,但是我比较习惯以最左最下的点做基准来极角排序【注意:如果有几点在凸包的同一条边上,那么需要把中间的点都去掉,只留下两段的点,这样好处理】,一下的算法都建立在之上。)首先我们设这个基准点为
假设对于
那么如何找
【注意:此题很多边界条件,坑爆了,还有极角序最大最小的凸包上的点可能要特判等等。。。。。。反正我是无限
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;
const double eps=1e-8;
int n,k,m;
int ff=0;
int up=-2e9+1,down=2e9+1;
struct dian_
{
int x,y;
double k;
}dian[100010]={{0,0,0}},cx[100010]={{0,0,0}};
int cxp=0;
int hash[100010]={0};
int np=0;
bool cmp(struct dian_ a1,struct dian_ a2)
{return a1.k>a2.k;}
long double counts(struct dian_ a1,struct dian_ a2,struct dian_ bb)
{return fabs((long double)(a1.x-bb.x)*(a2.y-bb.y)-(long double)(a2.x-bb.x)*(a1.y-bb.y))/2;}
bool check(int a1,int a2,int bb)
{
long double area1=counts(dian[a1],dian[a2],dian[1]);
long double area2=counts(dian[a1],cx[bb],dian[1])+counts(dian[a2],cx[bb],dian[1]);
if(area2<=area1+eps) return true;
else return false;
}
int main()
{
scanf("%d%d%d",&n,&m,&k);
ff=1;
for(int i=1;i<=n;i++)
{
scanf("%d%d",&dian[i].x,&dian[i].y);
if(dian[i].x<dian[ff].x || (dian[i].x==dian[ff].x && dian[i].y<dian[ff].y))
ff=i;
}
swap(dian[1],dian[ff]);
up=dian[1].y,down=dian[1].y;
for(int i=2;i<=n;i++)
{
if(dian[1].x==dian[i].x)
{
dian[i].k=(dian[i].y>dian[1].y?1:-1)*(2e9+1);
up=max(up,dian[i].y);
down=min(down,dian[i].y);
}
else dian[i].k=(double)(dian[i].y-dian[1].y)/(dian[i].x-dian[1].x);
}
sort(dian+2,dian+n+1,cmp);
for(int i=1;i<=m;i++)
{
int p,q;
scanf("%d%d",&p,&q);
if(p<dian[1].x)
continue;
if(p==dian[1].x)
{
if(q<=up && q>=down)
k--;
continue;
}
cxp++;
cx[cxp].x=p,cx[cxp].y=q;
cx[cxp].k=(double)(cx[cxp].y-dian[1].y)/(cx[cxp].x-dian[1].x);
}
sort(cx+1,cx+cxp+1,cmp);
for(int i=3;i<=n;i++)
{
if(counts(dian[i],dian[i-1],dian[1])<=eps)
{
hash[i-1]=1;
if(dian[i-1].x>dian[i].x)
dian[i]=dian[i-1];
}
}
for(int i=1;i<=n;i++)
if(hash[i]==0)
dian[++np]=dian[i];
int cnt=2;
for(int i=1;i<=cxp;i++)
{
int flag=0;
if(counts(cx[i],dian[cnt],dian[1])<=eps)
if(cx[i].x<=dian[cnt].x)
{
k--;
continue;
}
for(;cnt<=np && cx[i].k<dian[cnt].k;cnt++)
if(counts(cx[i],dian[cnt],dian[1])<=eps)
if(cx[i].x<=dian[cnt].x)
{
k--;
flag=1;
break;
}
if(flag==1) continue;
if(cnt==2) continue;
if(cnt==n+1) continue;
if(check(cnt-1,cnt,i)==true)
k--;
}
if(k<=0) puts("YES");
else puts("NO");
return 0;
}
标签:
原文地址:http://blog.csdn.net/qq_21995319/article/details/45955039