xiaolou @ 2018-10-04 13:14:35
https://www.luogu.org/record/show?rid=11467018//23333222
#include <bits/stdc++.h>
using namespace std;
char m[1005][1005];
bool vis[1005][1005];
struct Node
{
int x,y;
int step;
};
int movex[4]={0,0,1,-1};
int movey[4]={1,-1,0,0};
queue <Node> q;
int n;
int bfs(int x,int y,int endx,int endy)
{
Node now;
now.x=x;
now.y=y;
now.step=0;
q.push(now);
while(!q.empty())
{
now=q.front();
q.pop();
for(int i=0;i<4;i++)
{
Node next;
next.x=now.x+movex[i];
next.y=now.y+movey[i];
if(next.x>=1&&next.y>=1||next.x<=n&&next.y<=n&&vis[next.x][next.y]==false&&m[next.x][next.y]=='0')
{
if(next.x==endx&&next.y==endy)
return next.step;
vis[next.x][next.y]=true;
next.step=now.step+1;
q.push(next);
}
}
}
}
int main()
{
cin >> n;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
cin >> m[i][j];
int x,y;
cin >> x >> y;
int endx,endy;
cin >> endx >> endy;
cout << bfs(x,y,endx,endy);
return 0;
}
by xiaolou @ 2018-10-04 13:45:53
要开二维数组的话怎么办呢。。。@NaCly_Fish
by NaCly_Fish @ 2018-10-04 13:46:21
bitset<1003> vis[1003];
(应该)就行吧。。。
by xiaolou @ 2018-10-04 13:46:32
@P_Wang 智慧吧。。。
by 小略 @ 2018-10-04 13:46:48
@xiaolou 智慧吧......
by xiaolou @ 2018-10-04 13:49:19
@NaCly_Fish A了,感谢大佬
by NaCly_Fish @ 2018-10-04 13:55:12
@xiaolou QAQ
by xiaolou @ 2018-10-04 13:57:40
@小略 lzy智慧吧
by eros1on @ 2018-10-04 13:57:52
@xiaolou 智慧吧
by 小略 @ 2018-10-04 13:59:05
@xiaolou gyq智慧吧!
by xiaolou @ 2018-10-04 14:30:18
@小略 lzy智慧吧