【O(nlgn)判定点在凸包内】Codeforces Round #113 (Div. 2) B

思路参考了这个bloghttp://hi.baidu.com/aekdycoin/blog/item/7abf85026f0d7e85d43f7cfe.html

复杂度是O(nlgn)

#define N 100005
struct node{
    double x,y;
}a[100005];
double cross(node a,node b,node c){//>0,ab在ac顺时针;<0,ab在ac逆时针
    return (b.x-a.x)*(c.y-a.y) - (c.x-a.x)*(b.y-a.y);
}
int n,m;
bool chk(node b){
    int i,j;
    if(cross(a[0],b,a[1]) <= 0)return false;
    if(cross(a[0],b,a[n-1]) >= 0)return false;
    int l = 0,r = n-1,mid;
    int tag = 0;
    while(l<=r){
        mid = (l+r)>>1;
        if(cross(a[0],b,a[mid]) >= 0){
            tag = mid;
            l = mid+1;
        } else r = mid-1;
    }
    l = tag,r = tag+1;
    if(cross(a[l],b,a[r]) <= 0)return false;
    return true;
}

int main(){
    cin>>n;
    int i,j;
    for(i=0;i<n;i++){
        cin>>a[i].x>>a[i].y;
    }
    int ans = 0;
    cin>>m;
    node b;
    for(i=0;i<m;i++){
        cin>>b.x>>b.y;
        if(chk(b))ans++;
    }
    if(ans==m)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}





















  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值