社区讨论
o2优化?
P1332血色先锋队参与者 3已保存回复 2
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 2 条
- 当前快照
- 1 份
- 快照标识符
- @lo7r5q7d
- 此快照首次捕获于
- 2023/10/27 06:25 2 年前
- 此快照最后确认于
- 2023/10/27 06:25 2 年前
CPP
#include<bits/stdc++.h>
#include<queue>
using namespace std;
int n,m,a,b;
int x,y;
int f[502][502];
int go[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
struct node{
int x,y,time;
};
queue<node> q;
bool vis[502][502];
int bfs(){
while(!q.empty()){
node tmp=q.front();
q.pop();
for(int i=0;i<4;i++){
int xx=tmp.x+go[i][0];
int yy=tmp.y+go[i][1];
if(xx>=1&&xx<=n&&yy>=1&&yy<=m&&!vis[xx][yy]){
vis[xx][yy]=true;
f[xx][yy]=tmp.time+1;
q.push((node){xx,yy,tmp.time+1});
}
}
}
}
int main(){
cin>>n>>m>>a>>b;
for(int i=1;i<=a;i++){
cin>>x>>y;
q.push((node){x,y,0});
f[x][y]=0;
vis[x][y]=true;
}
bfs();
for(int i=1;i<=b;i++){
cin>>x>>y;
cout<<f[x][y]<<"\n";
}
return 0;
}
此代码不开o2AC,开o2全RE,为什么?
回复
共 2 条回复,欢迎继续交流。
正在加载回复...