记录编号 |
570970 |
评测结果 |
AAAAAAAAAAAAA |
题目名称 |
[USACO Feb07] 青铜莲花池 |
最终得分 |
100 |
用户昵称 |
┭┮﹏┭┮ |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.000 s |
提交时间 |
2022-04-28 19:53:58 |
内存使用 |
0.00 MiB |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
int n,m,n1,m1,x2,y2,x3,y3,l,r,s;
int a[50][50],x[10],y[10],b[500][3];
bool v[50][50];
void bfs(){
while(l < r){
for(int i = 1;i <= 8;i++){
int x4 = b[l][0]+x[i],y4 = b[l][1]+y[i];
if(a[x4][y4] == 0 || x4 < 1 || x4 > m || y4 < 1 || y4 > n || v[x4][y4])continue;
v[x4][y4] = 1;
b[r][0] = x4,b[r][1] = y4,b[r][2] = b[l][2] + 1;
r++;
if(x4 == x3 && y3 == y4){
printf("%d\n",b[r-1][2]);
break;
}
}
l++;
}
}
int main(){
freopen("bronlily.in","r",stdin);
freopen("bronlily.out","w",stdout);
scanf("%d%d%d%d",&m,&n,&m1,&n1);
x[1] = n1,x[2] = n1,x[3] = -n1,x[4] = -n1,x[5] = m1,x[6] = m1,x[7] = -m1,x[8] = -m1;
y[1] = m1,y[2] = -m1,y[3] = m1,y[4] = -m1,y[5] = n1,y[6] = -n1,y[7] = n1,y[8] = -n1;
for(int i = 1;i <= m;i++){
for(int j = 1;j <= n;j++){
scanf("%d",&a[i][j]);
if(a[i][j] == 3)x2 = i,y2 = j;
else if(a[i][j] == 4)x3 = i,y3 = j;
else if(a[i][j] != 1)a[i][j] = 0;
}
}
b[0][0] = x2,b[0][1] = y2;
v[x2][y2] = 1;
r++;
bfs();
return 0;
}