记录编号 |
553860 |
评测结果 |
AAAAAAAAAAAAA |
题目名称 |
[USACO Feb07] 青铜莲花池 |
最终得分 |
100 |
用户昵称 |
城南花已开 |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.000 s |
提交时间 |
2020-08-28 23:03:59 |
内存使用 |
0.00 MiB |
显示代码纯文本
# include <iostream>
# include <cstdio>
using namespace std;
int main(){
int m,n,m1,m2,pool1[31][31],head=0,tail=1,startx,starty,sum[902],i,j,qx[902],qy[902];
bool pool2[31][31];
freopen("bronlily.in","r",stdin);
freopen("bronlily.out","w",stdout);
scanf("%d%d%d%d",&m,&n,&m1,&m2);
for(i=1;i<=m;i++){
for(j=1;j<=n;j++){
pool2[i][j]=true;
}
}
for(i=1;i<=m;i++){
for(j=1;j<=n;j++){
scanf("%d",&pool1[i][j]);
if(pool1[i][j]==3){
startx=i;
starty=j;
}
if(pool1[i][j]==0||pool1[i][j]==2){
pool2[i][j]=false;
}
}
}
int heng[9]={0,m1,m1,-m1,-m1,m2,m2,-m2,-m2},shu[9]={0,m2,-m2,m2,-m2,m1,-m1,m1,-m1};
qx[1]=startx;
qy[1]=starty;
sum[1]=0;
pool2[startx][starty]=false;
do{
head++;
for(i=1;i<=8;i++){
if(qx[head]+heng[i]>=1&&qx[head]+heng[i]<=m&&qy[head]+shu[i]>=1&&qy[head]+shu[i]<=n){
if(pool2[qx[head]+heng[i]][qy[head]+shu[i]]==true){
tail++;
qx[tail]=qx[head]+heng[i];
qy[tail]=qy[head]+shu[i];
sum[tail]=sum[head]+1;
pool2[qx[tail]][qy[tail]]=false;
if(pool1[qx[tail]][qy[tail]]==4){
printf("%d",sum[tail]);
head=tail;
break;
}
}
}
}
}while(head<tail);
fclose(stdin);
fclose(stdout);
return 0;
}