menkeming @ 2023-11-26 11:45:15
#include<bits/stdc++.h>
using namespace std;
struct node{
int x,y;
};
int n,m,vis[1010][1010];
char mapp[1010][1010];
int dx[4]={0,1,0,-1};
int dy[4]={-1,0,1,0};
queue<node>q;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
cin>>mapp[i][j];
for(int i=0;i<m;i++){
memset(vis,0,sizeof(vis));
node st,now,nxt;
int ans=1;
cin>>st.x>>st.y;
q.push(st);
vis[st.x][st.y]=1;
while(!q.empty()){
now=q.front();
q.pop();
for(int j=0;j<4;j++){
nxt.x=now.x+dx[j];
nxt.y=now.y+dy[j];
if(nxt.x>0&&nxt.y>0&&nxt.x<=n&&nxt.y<=n&&
vis[nxt.x][nxt.y]==0&&
((mapp[now.x][now.y]=='0'&&mapp[nxt.x][nxt.y]=='1')
||(mapp[now.x][now.y]=='1'&&mapp[nxt.x][nxt.y]=='0'))){
vis[nxt.x][nxt.y]=1;
q.push(nxt);
ans++;
}
}
if(ans==n*n) break;
}
cout<<ans<<'\n';
}
}
by bookvalley @ 2024-01-04 11:54:15
???
by Potato_404 @ 2024-02-25 22:00:15
你用快读干啥啊 和那个没关系吧 是不是你多写了一个判断
by menkeming @ 2024-09-24 21:51:58
怎么改?