Delayed @ 2024-08-08 17:15:35
#include<bits/stdc++.h>
using namespace std;
const int N=1000+10;
int n,m,D[N][N],vis[10005][10005],ans;
char my_map;
int X[10]={0,1,-1,0,0};
int Y[10]={0,0,0,1,-1};
struct node{
int xxx;
int yyy;
};
void bfs(int a,int b)
{
// cout<<a<<" "<<b<<endl;
queue<node>q;
vis[a][b]=1;
// cout<<endl;
// cout<<"vis"<<endl;
// for(int i=1;i<=n;i++){
/// for(int j=1;j<=n;j++){
// cout<<vis[i][j]<<" ";
// }
// cout<<endl;
// }
// cout<<endl;
q.push({a,b});
while(!q.empty()){
node now=q.front();
// cout<<"now:"<<now.xxx<<" "<<now.yyy<<endl;
q.pop();
for(int i=1;i<=4;i++){
int xx=now.xxx+X[i];
int yy=now.yyy+Y[i];
// cout<<"xx,yy"<<xx<<" "<<yy<<endl;
if(xx<=n || yy<=n || xx>0 || yy>0|| vis[xx][yy]==0){
if(D[now.xxx][now.yyy]==1){
//cout<<"进1";
if(D[xx][yy]==1 ) continue;
ans++;
//cout<<"ans:"<<ans<<endl;
q.push({xx,yy});
}
if(D[now.xxx][now.yyy]==0){
//cout<<"进0"<<endl;
if(D[xx][yy]==0) continue;
ans++;
//cout<<"ans:"<<ans<<endl;
q.push({xx,yy});
}
}
}
}
//cout<<ans+1<<endl;
ans=0;
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cin>>my_map;
if(my_map=='1')D[i][j]=1;
if(my_map=='0')D[i][j]=0;
}
}
for(int i=1;i<=m;i++){
int x,y;
cin>>x>>y;
bfs(x,y);
memset(vis,0,sizeof(vis));
}
return 0;
}
by Into_the_Abyss @ 2024-08-08 19:08:30
qwq
by Delayed @ 2024-08-11 08:41:31
@Into_the_Abyss
//gaigai
cout<<"风里雨里,我在等你";
by Into_the_Abyss @ 2024-08-11 08:42:28
@Delayed 油饼