44i11 @ 2024-01-31 09:51:56
#include<bits/stdc++.h>
using namespace std;
struct node{
int x,y;
node(){}
node(int xx,int yy){
x=xx,y=yy;
}
};
queue<node>q;
int dd[4][2]={{1,0},{-1,0},{0,1},{0,-1}},n,m,vis[1005][1005];
int s[1005][1005];
void bfs(int sx,int sy){
int ans=0;
memset(vis,0,sizeof(vis));
q.push(node(sx,sy));
while(!q.empty()){
node no=q.front();
q.pop();
for(int i=0;i<4;i++){
int xx=no.x+dd[i][0];
int yy=no.y+dd[i][1];
if(xx<0||yy<0||xx>=n||yy>=n||s[xx][yy]==s[no.x][no.y]||vis[xx][yy]){
continue;
}
vis[xx][yy]=1;
q.push(node(xx,yy));
ans++;
}
}
cout<<ans<<endl;
}
int main(){
cin>>n>>m;
for(int i=0;i<n;i++){
char ch=getchar();
for(int j=0;j<n;j++){
char c=getchar();
if(c=='0'){
s[i][j]=0;
}else{
s[i][j]=1;
}
}
}
while(m--){
int sx,sy;
cin>>sx>>sy;
bfs(sx-1,sy-1);
}
return 0;
}
by yjjimpaopao @ 2024-02-02 14:57:59
只输个1x1的0就是错的啊,答案不应该是1吗,怎么输出的0