0分求调
  • 板块灌水区
  • 楼主Hyvial
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/5/6 21:42
  • 上次更新2024/5/7 12:29:36
查看原帖
0分求调
1137394
Hyvial楼主2024/5/6 21:42

原题在这里

为什么这道题会错qwq,我没找到啊。

#include <bits/stdc++.h>
#define LL long long
#define DB double
#define BUG cout << "OoO" << endl

using namespace std;

const int N = 1001, Max_N = 1000001;
int n, m, ax, ay;
string st[N];
int d, mp[N][N], vis[N][N], ans[Max_N];
int dx[] = {0, 0, -1, 1}, dy[] = {-1, 1, 0, 0};
struct Node {int x, y;};


void BFS(int ax, int ay, int d)
{
	int ret = 1;
	queue <Node> q; 
	q.push(Node{ax, ay});
	vis[ax][ay] = d;
	
	while(!q.empty())
	{
		Node u = q.front();
		q.pop();
		
		for(int i = 0; i < 4; i ++ )
		{
			int xx = u.x + dx[i];
			int yy = u.y + dy[i];
			
			if(vis[xx][yy] == 0 && xx >= 0 && xx < n && yy >= 0 && yy < n && ((st[u.x][u.y] == '1' && st[xx][yy] == '0') || (st[u.x][u.y] == '0' && st[xx][yy] == '1')))
			{
				q.push(Node{xx, yy});
				ret ++ ;
				vis[xx][yy] = d;
			}
		}
	}
	
	ans[d] = ret;
}

int main()
{
	scanf("%d%d", &n, &m);
	
	for(int i = 1; i <= n; i ++ )
		cin >> st[i];
	
	memset(vis, 0, sizeof vis);
	cout << st[5][1] << ' ' << st[5][2] << endl;
	while(m -- ) 
	{	
		cin >> ax >> ay;
		ax -- , ay -- ;
		
		if(vis[ax][ay] == 0)
		{
//			printf("%d\n", d);
			d ++ ;
			BFS(ax, ay, d);
		}
			
//		for(int i = 0; i < n; i ++ )
//		{
//			for(int j = 0; j < n; j ++ )
//				printf("%d ", vis[i][j]);
//			puts("");
//		}
		
		printf("%d\n", ans[vis[ax][ay]]);
	}
	
	for(int i = 0; i < n; i ++ )
	{
		for(int j = 0; j < n; j ++ )
			printf("%d ", ans[vis[i][j]]);
		puts("");
	}
	
	
    return 0;
}
2024/5/6 21:42
加载中...