社区讨论
广搜80分 第九第十个点tle
P114101迷宫参与者 3已保存回复 5
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 5 条
- 当前快照
- 1 份
- 快照标识符
- @mi7clp1a
- 此快照首次捕获于
- 2025/11/20 19:28 4 个月前
- 此快照最后确认于
- 2025/11/20 19:28 4 个月前
麻烦看看
CPP#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
int ch[4][2]={{-1,0},{0,-1},{1,0},{0,1}};
char board[1005][1005];
int book[1005][1005];
int num=10;
int n,m;
void bfs(int,int);
queue<int>h;
queue<int>l;
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
scanf("%s",&board[i][1]);
int x,y;
for(int i=1;i<=m;i++)
{
scanf("%d%d",&x,&y);
bfs(x,y);
}
return 0;
}
void bfs(int u,int v)
{
num++;
int step=1;
book[u][v]=num;
h.push(u);
l.push(v);
int q1,q2;
while(!h.empty())
{
for(int i=0;i<4;i++)
{
q1=h.front()+ch[i][0];
q2=l.front()+ch[i][1];
if(book[q1][q2]==num)
continue ;
if(q1>=1 and q1<=n and q2>=1 and q2<=n and board[q1][q2]-'0'==abs(board[h.front()][l.front()]-'0'-1))
{
book[q1][q2]=num;
step++;
if(step==n*n)
break ;
h.push(q1);
l.push(q2);
}
}
h.pop();
l.pop();
if(step==n*n)
break;
}
printf("%d\n",step);
}
回复
共 5 条回复,欢迎继续交流。
正在加载回复...