NOIP2017TG D2T1 cheese

Topic Link

 

Meaning of the questions:

Space, like some of the known distribution of the ball, and $ z = 0 $ and $ z = h $ two planes. Intersection of tangent or predetermined "link", connected components of the two planes.

 

Program (100pt):

Identify and upper, lower plane Unicom balls, for the sake of conversion of the two sets of communication, engage in a practice on a wide search of Europe.

Note that: Analyzing "link" with the condition Zhengshi squared, and precision to avoid dealing with.

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define IL inline
using namespace std;
typedef long long LL;
const LL N=1e3;

    int T,n;
    LL h,r;
    
struct Node{
    LL x,y,z;
    
}a[N+3];

    bool v[N+3];
    int q[N*4+3],hd,tl;

IL LL sq(LL x){
    return x*x;
    
}

IL bool acs(Node a,Node b){
    return sq(r*2)>=sq(a.x-b.x)
                   +sq(a.y-b.y)
                   +sq(a.z-b.z);
    
}

int main(){
    bool flag;
    int u;
    scanf("%d",&T);
    while(T--){
        scanf("%d%lld%lld",&n,&h,&r);
        for(int i=1;i<=n;i++)
            scanf("%lld%lld%lld",&a[i].x,&a[i].y,&a[i].z);
            
        memset(v,0,n+1);
        hd=1;    tl=0;
        for(int i=1;i<=n;i++)
        if(a[i].z<=r){
            q[++tl]=i;
            v[i]=true;
            
        }
        
        flag=false;
        while(hd<=tl){
            u=q[hd++];
            if(a[u].z+r>=h){
                flag=true;
                break;
                
            }
            for(int i=1;i<=n;i++)
            if(i!=u)
            if(acs(a[i],a[u]))
            if(!v[i]){
                q[++tl]=i;
                v[i]=true;
                
            }
                
        }
        
        if(flag)
            printf("Yes\n");
        else 
            printf("No\n");
        
    }
    
    return 0;
    
}

 

summary:

Energy topics not have much time to 5 minutes. This question is do I pay homage to the year of the league 50 points ......

Guess you like

Origin www.cnblogs.com/Hansue/p/10990809.html