[Los] p3958 Valley Cheese

[Link] title cheese

Premise nonsense do not know spade ah qwq (more quiet )

Well, look at the question:

SOLUTION:

Thinking it would probably be a search, then probably wide search? ? ?

But we write today deep search (also listen xcg chiefs spoke after finishing Bo)

First First read, pay attention because multiple sets of data, so be sure to remember to re-assign such as memset.

Then we can find from the lower surface of the cheese into the hole, the hole is clear that when a highly zr <= 0, can be adopted;

for(int i=1;i<=n;i++){
    if(a[i].z-r<=0)
       view [i] = 1 , dfs (i);
}

Then we can try pruning (pruning and pro-test after more slowly ???)

Pruning: because when a certain you can not, obviously higher than it will not work, then direct break;

Without the sort:


Plus the sort:

Then search:

End Condition: height z of a point in the + r> = h; while numerals bj = 1; represents solvable

Then enumerated points (each point enumerated herein dfs guaranteed only once, because the judgment is a solution, it is not necessary remember the path there is no need of the tube the influence of different paths)

If bj = 1, it has been found to represent a solution, you do not have to search directly break;

Otherwise, first determine:

1. This point has not been visited

2. The two space station are reachable (about connectivity, we can compare their size relationship between the distance and twice the radius of the circle, when the distance is less than twice the radius, connectivity)

If not visited and communication, dfs enumeration to a point, vis = 1;

Then finally determines bj = 1/0, corresponding to Yes / No;

CODE:

#include<bits/stdc++.h>
#define ll long long

using namespace std;

inline ll read(){
    ll ans=0;
    char last=' ',ch=getchar();
    while(ch>'9'||ch<'0') last=ch,ch=getchar();
    while(ch>='0'&&ch<='9') ans=(ans<<1)+(ans<<3)+ch-'0',ch=getchar();
    if(last=='-') ans=-ans;
    years;return
}

ll t,n,h,r;
bool vis[1001],bj;
struct node{
    ll x,y,z;
}a[1001];
bool cmp(node a,node b){
    return a.z<b.z;
}

double dis(ll x1,ll y1,ll z1,ll x2,ll y2,ll z2){
    return sqrt((double)(x1-x2)*(double)(x1-x2)+(double)(y1-y2)*(double)(y1-y2)+(double)(z1-z2)*(double)(z1-z2));
}

void dfs(ll k){
    if(a[k].z+r>=h){
        bj=1;
        return;
    }
    for(int i=1;i<=n;i++){
        if(bj) return;
        if(!vis[i]&&dis(a[i].x,a[i].y,a[i].z,a[k].x,a[k].y,a[k].z)<=2.0*r){
            view [i] = 1 ;
            dfs(i);
        }
    }
}

int main () {
    t=read();
    for(int T=1;T<=t;T++){
        n=read();h=read();r=read();
        bj=0;
        memset(vis,0,sizeof(vis));
        for(int i=1;i<=n;i++){
            a[i].x=read();
            a[i].y=read();
            a[i].z=read();
        }
            
        sort(a+1,a+n+1,cmp);
        for(int i=1;i<=n;i++){
            if(bj) break;
            if(a[i].z-r<=0)
              view [i] = 1 , dfs (i);
            else  break ;
        }
        if(bj) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}

 


Guess you like

Origin www.cnblogs.com/zhuier-xquan/p/11137422.html