# NOIP 2017 Day2 T1 cheese

Posted by namasteaz on Sat, 02 May 2020 22:22:53 +0200

luogu topic

The only conscience question in two days, however, I have 70% honey in the exam room

There should be a lot of practices, and simple practices should include collection and search;

I play and check the collection, but it seems like a group of DFS fast;

The idea is very simple. It is to combine the holes that can be connected together into one set;

Finally, we need to check whether the bottom and top surfaces are in the same set;

It's over (so naked, but I just don't have AC).

Complexity O (n2 × T)

AC code is as follows, personal feeling is still clear (244 ms 2183 kb):

```#include<bits/stdc++.h>    // NOIP can't write like this
#define m(a,b) memset(a,b,sizeof(a))    // Lazy...
#define ll long long
using namespace std;
int f[1002];
struct _{    // Structure representing the hole
int x,y,z;
}a[1002];
inline bool cmp(_ a,_ b){    // Used in quick arrangement
return a.z<b.z;
}
inline ll q(ll x){    // Square (not lazy yet)
return x*x;
}
inline double dis(_ a,_ b){    // Find the distance between two holes
return (double)sqrt(q(a.x-b.x)+q(a.y-b.y)+q(a.z-b.z));
}
int find(int x){    // Concurrent query set -- Query
if(f[x]==x) return x;
return f[x]=find(f[x]);
}
void bing(int a,int b){    // Parallel search set -- merge
int x=find(a),y=find(b);
f[x]=y;
}
inline void init(){    // Initialization, handling multiple groups of data
m(a,0),m(f,0);
}
int main(){
int n,t,h,r;
scanf("%d",&t);
while(t--){
init();
scanf("%d%d%d",&n,&h,&r);
for(int i=1;i<=n+1;i++) f[i]=i;    // 0 is the bottom, n+1 is the top
for(int i=1;i<=n;i++)
scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].z);
sort(a+1,a+n+1,cmp);    // Preprocessing, sorted by z, can speed up
for(int i=1;i<n;i++)
for(int j=i+1;j<=n&&a[j].z-(r<<1)<=a[i].z;j++)    // Jump out when the difference of height (z) is greater than 2*r
if(dis(a[i],a[j])<=r<<1) bing(i,j);
for(int i=1;i<=n;i++) if(a[i].z<=r) bing(0,i);    // Holes and both sides
for(int i=n;i>0;i--) if(a[i].z>=h-r) bing(i,n+1);    // Interlink
if(find(0)==find(n+1)) printf("Yes\n");
else printf("No\n");
}
return 0;    // Solemnly conclude the procedure
}```

%%%Write Dalao%%% of scanline

By the seven -- a new year's senior high school konjak

2017-12-23 18:08:34

Topics: C++