src2020/4072_fire/fire.cpp

36 lines
987 B
C++
Raw Normal View History

2020-04-04 10:37:59 +08:00
#include<iostream>//YOUWU
#include<cstring>
using namespace std;
int x[100000001]={0},y[100000001]={0},f[100000001]={0},fx[4]={0,0,1,-1},fy[4]={1,-1,0,0};
int main(){
char s[10][10];
for(int i=0;i<10;i++){
for(int j=0;j<10;j++){
cin>>s[i][j];
int u=s[i][j];
if(u=='L'){
x[1]=i,y[1]=j;
//cout<<endl<<x[1]<<y[1]<<endl;
}
}
}
int t=0,w=1;
do{
t++;
for(int i=0;i<4;i++){
int nx=x[t]+fx[i],ny=y[t]+fy[i];
//cout<<nx<<" "<<ny<<" "<<s[nx][ny]<<endl;
if(nx>=0&&nx<10&&ny>=0&&ny<10){
if(s[nx][ny]=='B'){
cout<<f[t];
return 0;
}
if(s[nx][ny]!='R'){
x[++w]=nx;
y[w]=ny;
f[w]=f[t]+1;
}
}
}
}while(t<w);
}