C_plus_plus_12345 @ 2024-12-20 20:45:32
#include<bits/stdc++.h>
using namespace std;
int u[5]={0, 0, 1, 0, -1},
w[5]={0, 1, 0, -1, 0};
int n, m, desx, desy, soux, souy, head, tail, x, y, a[101], b[101], pre[101], _map[101][101], sum;
char _map2[101][101];
bool f;
void out(int d)
{
if(pre[d]!=0)
{
out(pre[d]);
}
printf("%d, %d\n", a[d], b[d]);
++sum;
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>_map2[i][j];
if(_map2[i][j]=='.')
{
_map[i][j]=0;
}
else if(_map2[i][j]=='#')
{
_map[i][j]=-1;
}
}
}
soux = 1; souy = 1;
desx = n; desy = m;
head=0;tail=1;f=false;_map[soux][souy]=-1;
a[tail]=soux;b[tail]=souy;pre[tail]=0;
while(head!=tail)
{
head++;
for(int i=1;i<=4;i++)
{
x=a[head]+u[i];y=b[head]+w[i];
if((x>0)&&(x<=n)&&(y>0)&&(y<=m)&&_map[x][y]==0)
{
tail++;
a[tail]=x;b[tail]=y;pre[tail]=head;
_map[x][y]=-1;
if((x==desx)&&(y==desy))
{
f=true;
out(tail);
break;
}
}
}
if(f)
{
cout<<"Yes"<<endl;
break;
}
}
if(!f)
{
cout<<"No"<<endl;
}
return 0;
}
by Ekin123 @ 2024-12-20 21:17:48
@C_plus_plus_12345 请不要把某USACO的题的代码拿来凑数。
by C_plus_plus_12345 @ 2024-12-20 21:26:15
@Ekin123 我没有做那道 USACO 的题目,我搁书上扌
少的
by Ekin123 @ 2024-12-20 21:54:45
@C_plus_plus_12345 先把 out()
函数扔掉
by Ekin123 @ 2024-12-20 21:55:06
@Ekin123 你用不到