比赛 |
20220426小练习USACO Feb07 |
评测结果 |
AWTTTWWAWAAAT |
题目名称 |
青铜莲花池 |
最终得分 |
38 |
用户昵称 |
┭┮﹏┭┮ |
运行时间 |
4.000 s |
代码语言 |
C++ |
内存使用 |
1.77 MiB |
提交时间 |
2022-04-26 20:44:12 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
int n,m,n1,m1,x1,x2,y3,y2,ss = 9999999;
int x[10],y[10];
int a[50][50];
bool v[50][50];
void sou(int l,int r,int s){
if(l == x2 && r == y2){
if(ss > s)ss = s;
return;
}
if(a[l][r] == 0 || l < 1 || r < 1 || l > m || r > n || v[l][r])return;
v[l][r] = 1;
for(int i = 1;i <= 8;i++){
if(v[l+x[i]][r+y[i]] == 1)continue;
sou(l+x[i],r+y[i],s+1);
}
v[l][r] = 0;
}
int main(){
freopen("bronlily.in","r",stdin);
freopen("bronlily.out","w",stdout);
scanf("%d%d%d%d",&n,&m,&n1,&m1);
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 <= n;i++){
for(int j = 1;j <= m;j++){
scanf("%d",&a[i][j]);
if(a[i][j] == 3)x1 = i,y3 = j;
else if(a[i][j] == 4)x2 = i,y2 = j;
else if(a[i][j] != 1)a[i][j] = 0;
}
}
sou(x1,y3,0);
printf("%d\n",ss);
return 0;
}