[NOIp2017提高组]奶酪(BFS)


[NOIp2017提高组_Day2T1]奶酪

 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 }

优质内容筛选与推荐>>
1、ORACLE 横表与纵表
2、使用vs2005调试javascript
3、C#中的文件流学习笔记第一篇
4、Centos6.3建立FTP
5、Android UI学习 - TableLayout


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号