【 NOIP 2017 】【 奶酪 】

NOIP 2017 当时并没有做出来......

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define LL long long 
#define inf 0x7f7f7f7f7f7f7f7f
using namespace std;

inline int wread(){
	char c(getchar());int wans(0),flag(1);
	while (c<'0' || c>'9'){if (c=='-') flag=-1;c=getchar ();}
	while (c>='0' && c<='9'){wans=wans*10+c-'0';c=getchar();}
	return wans*=flag;
}
inline LL ll_wread(){
	char c(getchar());LL wans(0),flag(1);
	while (c<'0' || c>'9'){if (c=='-') flag=-1;c=getchar();}
	while (c>='0' && c<='9'){wans=wans*10+c-'0'; c=getchar();}
	return wans*=flag;
}
int T;
struct node{int x,y;LL z;}e[1005];
bool vis[1005];
int S[1005],top;
int f[1005];
LL max (LL a,LL b){return a>b?a:b;}
LL cal_dis (int a,int b){
	return (LL)(e[a].x - e[b].x) *(LL)(e[a].x - e[b].x) + (LL) (e[a].y - e[b].y) * (LL) (e[a].y - e[b].y) + (LL) (e[a].z - e[b].z) * (LL) (e[a].z - e[b].z);
}
int fnd(int x){return x==f[x]?x:f[x]=fnd(f[x]);}

int main(){
	T=wread();
	while (T--){
		top=0;
		memset (vis,false,sizeof vis);
		int n(wread()),h(wread()),r(wread());
		for (int i(1);i<=n;++i){
			e[i].x=wread(),e[i].y=wread();e[i].z=ll_wread();	
			if (e[i].z-(LL)r<=0) S[++top]=i;
		}
		
		for (int i(1);i<=n;++i)	f[i]=i;
		
		for (int i(1);i<=n;++i)
			for (int j(i+1);j<=n;++j){
				if (cal_dis(i,j)>(4*(LL)r*(LL)r))	continue;
				else {
					int fx=fnd(i),fy=fnd(j);
					if (fx!=fy)		f[fy]=fx;
				}
			}
			
		bool Y=false;
		for (int i(1);i<=top;++i){
			if (Y)	break;
			int poit=S[i];
			int fx=fnd(poit);
			if (vis[fx])	continue;
			vis[fx]=true;
			LL up_h=-inf;
			for (int j(1);j<=n;++j){
				if (fnd(j)!=fx)	continue;
				up_h=max(up_h,e[j].z+(LL)r);
			}
			if (up_h >=(LL) h) 	Y=true;
		}
		if (Y)	puts("Yes");
		else puts("No");
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/violinlove/article/details/81366542