[NOIp2017提高组]奶酪(BFS)
1 #include<iostream> 2 #include<stdio.h> 3 #include<vector> 4 #include<queue> 5 #include<math.h> 6 #include<string.h> 7 #define LL long long 8 using namespace std; 9 LL read() 10 { 11 long long sign=1,num=0; 12 char ch=getchar(); 13 while(!isdigit(ch)){if(ch=='-')sign=-1;ch=getchar();} 14 while(isdigit(ch)){num=num*10+(ch-'0');ch=getchar();} 15 return sign*num; 16 } 17 LL h,r,t,n,bol,temp,book[1010],f[1010][1010]; 18 struct set{LL x,y,z;}; 19 vector<set > v; 20 queue<int > q; 21 double DIS(set bufx,set bufy)//用整形影响精度 22 { 23 return sqrt((bufx.x-bufy.x)*(bufx.x-bufy.x)+(bufx.y-bufy.y)*(bufx.y-bufy.y)+(bufx.z-bufy.z)*(bufx.z-bufy.z)); 24 } 25 int main() 26 { 27 t=read(); 28 while(t--) 29 { 30 n=read(); 31 h=read(); 32 r=read(); 33 v.clear(); 34 bol=1; 35 while(!q.empty())q.pop(); 36 memset(f,0,sizeof(f)); 37 for(int i=1;i<=n;++i) 38 { 39 set buf; 40 buf.x=read(); 41 buf.y=read(); 42 buf.z=read(); 43 v.push_back(buf); 44 } 45 for(int i=0;i<n;++i) 46 for(int j=0;j<n;++j) 47 if(DIS(v[i],v[j])<=2*r) 48 { 49 f[i][j]=1; 50 f[j][i]=1; 51 } 52 for(int i=0;i<n && bol;++i) 53 { 54 if(v[i].z-r>0)continue; 55 memset(book,0,sizeof(book)); 56 q.push(i); 57 book[i]=1; 58 while(!q.empty()) 59 { 60 temp=q.front(); 61 if(v[temp].z+r>=h) 62 { 63 printf("Yes\n"); 64 bol=0; 65 break; 66 } 67 for(int j=0;j<n;++j) 68 { 69 if(f[temp][j] && !book[j]) 70 { 71 book[j]=1; 72 q.push(j); 73 } 74 } 75 q.pop(); 76 } 77 } 78 if(bol)printf("No\n"); 79 } 80 }优质内容筛选与推荐>>