zoukankan      html  css  js  c++  java
  • [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
    ");
    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
    ");
    79     }
    80 }
  • 相关阅读:
    Intersection of Two Linked Lists
    Tools:实现vmware虚拟机开机自启动
    Tools:实现ping操作带时间戳【windows+linux】
    Django:学习笔记
    Python:笔记2
    Python:笔记1_字符串处理【转载】
    Pycharm:使用笔记
    python:win下将py文件打包成exe
    python:选房抽签小工具
    RF:操作笔记
  • 原文地址:https://www.cnblogs.com/__Kgds/p/9482103.html
Copyright © 2011-2022 走看看