NOIP 2016 cheese

So the water problem took only 80 minutes? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

qaq awsle

sqrt pay attention to accuracy problems, it is best not to prescribe relatively squared away to avoid accuracy problems

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring> 
#include<cmath>
using namespace std;
struct pp{
    long long x;
    long long y;
    long long z;
    long long v;
    
}e[60002];
long long t,n,m,res,ans,cnt,num,h,r,u1,d1;
int up[60002],down[60002],vis[60002];
long long dis(pp x,pp y ){
    return (x.x-y.x)*(x.x-y.x)+(x.y-y.y)*(x.y-y.y)+(x.z-y.z)*(x.z-y.z);
}
bool jud(pp x,pp y){
    if(dis(x,y)<=(r*2)*(r*2)) return 1;
    return 0;
}
bool dfs(pp x){
    vis[x.v]=1;
    if(up[x.v]) {
        return 1;
    }
    for(int i=1;i<=n;i++){
        if(vis[e[i].v]) continue;
        if(jud(x,e[i])){
            if(dfs(e[i]))
            return 1;
        }
    }
    return 0;
}
int main(){
    scanf("%lld",&t);
    while(t--){
        scanf("%lld%lld%lld",&n,&h,&r);
        ans=0;
        d1=0;
        memset(vis,0,sizeof(vis));
        memset(up,0,sizeof(up));
        for(int i=1;i<=n;i++){
            scanf("%lld%lld%lld",&e[i].x,&e[i].y,&e[i].z);
            e[i].v=i;
            if(e[i].z+r>=h) up[i]=1;
            if(e[i].z-r<=0) down[++d1]=i;
        }
        for(int i=1;i<=d1;i++){
            if(vis[e[down[i]].v]) continue;
            if(dfs(e[down[i]])){
                ans=1;
                break;
            }
        }
        if(ans==1) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}
cheese

 

Guess you like

Origin www.cnblogs.com/xwx2354672579/p/11616811.html