“生化武器”

                      “生化武器”

 

Description

 

在一个封闭的房间里,gogo给大家表演了他的屁遁术,人果然一下没影了,但是他留下的“生化武器”,却以每秒1米的速度向上下左右扩散出去。为了知道自己会不会被“毒”到,你果断写了个算法计算出了“毒气”在t秒时间内可以到达的所有地方。

 

Input

有多组测试数据

第一行输入n,m,t(0<n,m<=30)

n和m表示图的行和列,t表示时间 ,‘*’为表演的地点,‘X’是墙,‘.’为空白的地方

 

Output

如果在t秒时间内毒气没有充满房间或刚好充满,输出现在房间里的情况,‘#’表示有‘毒气’的地方

否则,输出“No”

每组数据输出后有一个空行

 

Sample Input

 

9 9 4
XXXXXXXXX
X...X...X
X.*.....X
X...X...X
XXXXXXXXX
X...X
X...X
X...X
XXXXX

5 5 2
XXXXX
X...X
X.*.X
X...X
XXXXX

 

Sample Output

 

XXXXXXXXX
X###X#..X
X######.X
X###X#..X
XXXXXXXXX
X...X
X...X
X...X
XXXXX

XXXXX
X###X
X###X
X###X
XXXXX

 

# include<stdio.h>
# include<string.h>
# include<queue>
using namespace std;
char Map[40][40]; 
int vis[40][40];
int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
int leap;
struct node
{
    int step;
    int tx,ty;
}p;
void bfs(int x,int y,int t)
{
    queue<node>C;
    int i;
   vis[x][y]=1;
   Map[x][y]='#';
   p.step=0;
   p.tx=x;
   p.ty=y;
   C.push(p);
   while(!C.empty())
   {
      node a=C.front();
      C.pop();
      if(a.step==t)
      {
          return;
      }
      for(i=0;i<4;i++)
      {
          node b;
          b.tx=a.tx+dir[i][0];
          b.ty=a.ty+dir[i][1];
          if(Map[b.tx][b.ty]!='X'&&!vis[b.tx][b.ty])
          {
              vis[b.tx][b.ty]=1;
          Map[b.tx][b.ty]='#';
          b.step=a.step+1;
          C.push(b);
          }
      }
   }
   printf("No\n");
   leap=1;
}
int main()
{
    int row,col,t,i,j,st,en;
    while(scanf("%d %d %d",&row,&col,&t)!=EOF)
    {
        leap=0;
        memset(vis,0,sizeof(vis));
        for(i=0;i<row;i++)//这道题值得一提的是输入方式,一行一行的输
        {
                scanf("%s",Map[i]);
        }
        for(i=0;i<row;i++)
        {
            for(j=0;j<col;j++)
            {
                if(Map[i][j]=='*')
                {
                    st=i;
                    en=j;
                }
            }
        }
        bfs(st,en,t);
        if(leap==0)
        {
        for(i=0;i<row;i++)
        {
printf("%s\n",Map[i]);
        }
        }
        printf("\n");
    }
    return 0;
}

 

posted on 2012-08-17 23:01  即为将军  阅读(331)  评论(0)    收藏  举报

导航