悬赏关注
  • 板块灌水区
  • 楼主hkl99
  • 当前回复4
  • 已保存回复4
  • 发布时间2024/9/17 23:11
  • 上次更新2024/9/18 16:44:24
查看原帖
悬赏关注
770439
hkl99楼主2024/9/17 23:11

为啥全部RE

题目

#include<bits/stdc++.h>
using namespace std;
int n,m,a[1001][1001],x,y,fx[4][2]= {{1,0},{-1,0},{0,1},{0,-1}},d,c[100001],flag[1001][1001];
struct node {
	int x,y,z;
};
int bfs() {
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=n; j++) {
			if(flag[i][j]==0) {
				int cnt=0;
				queue<node>q;
				node t;
				t.x=i;
				t.y=j;
				t.z=a[i][j];
				flag[i][j]=++d;
				q.push(t);
				while(!q.empty()) {
					t=q.front();
					q.pop();
					int nx,ny;
					for(int i=0; i<4; i++) {
						node tt;
						tt.x=t.x+fx[i][0];
						tt.y=t.y+fx[i][1];
						if(tt.x>=1&&tt.y>=1&&tt.x<=n&&tt.y<=n&&flag[tt.x][tt.y]==0&&a[tt.x][tt.y]==(0-t.z)) {
							cnt++;
							flag[tt.x][tt.y]=d;
							tt.z=0-t.z;
							q.push(tt);
						}
					}
				}
				c[d]=cnt;
			}
		}
	}

}
int main() {
	scanf("%d%d",&n,&m);
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=n; j++) {
			scanf("%1d",&x);
			a[i][j]=x;
			if(x==0) {
				a[i][j]=-1;
			}
		}
	}
	bfs();
	for(int i=1; i<=m; i++) {
		cin>>x>>y;
		printf("%d\n",c[flag[x][y]]+1);
	}
	return 0;
}
2024/9/17 23:11
加载中...