题解:P15056 [UOI 2023 II Stage] Unenslaved puppy

· · 题解

P15046

思路

考虑初中距离公式,ab 的距离 len_{a,b}=\sqrt{(x_a-x_b)^2+(y_a-y_b)^2},每个在半圆内的点 a 与圆心 pos_i 都满足 len_{pos_i,a}≤r,判断狗,蜜蜂与半圆的位置关系,一个在圆内,一个在圆外时即为解。

代码

#include<bits/stdc++.h>

using namespace std;
int n;
double x1,y1,x2,y2,p,r;
int check(double x,double y,double p,double r){
    double len=sqrt(1.0*pow(p-x,2)+1.0*pow(y,2));
    if(len<=r)return 1;
    return 0;
}
signed main(){
    cin>>n>>x1>>y1>>x2>>y2;
    for(int i=1;i<=n;i++){
        cin>>p>>r;
        int c1=check(x1,y1,p,r);//求与圆的关系
        int c2=check(x2,y2,p,r);
        if(c1^c2){//一个外,一个内
            cout<<"NO"<<endl;
            cout<<i;
            return 0;
        }
    }
    cout<<"YES";
    return 0;
}