《我一直以为写代码是放松的》
  • 板块灌水区
  • 楼主_AC_IS_GOD_QP_
  • 当前回复5
  • 已保存回复5
  • 发布时间2024/7/20 14:46
  • 上次更新2024/7/20 15:44:31
查看原帖
《我一直以为写代码是放松的》
744442
_AC_IS_GOD_QP_楼主2024/7/20 14:46

直到他把我折磨得心力憔悴

#include<bits/stdc++.h>
using namespace std;
struct node{
	int w_n,r,c;
};
int n,m;
bool a[1005][1005];
int maxx=-1e9;
queue<node> Q;
int main(){
	
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			int R;
			scanf("%01d",&R);
			a[i][j]=R;
		}
	}
	while(m--){
		node init;
		init.w_n=1;
		int r1,c1;
		cin>>r1>>c1;
		init.r=r1;
		init.c=c1;
		Q.push(init);
		while(Q.size()){
			bool flag=false;
			node L=Q.front();
			if(L.c-1>0&&a[L.r][L.c-1]!=a[L.r][L.c]){
				L.c--;
				L.w_n++;
				Q.push(L);
				flag=true;
			}
			L=Q.front();
			if(L.c+1<=n&&a[L.r][L.c+1]!=a[L.r][L.c]){
				L.c++;
				L.w_n++;
				Q.push(L);
				flag=true;
			}
			L=Q.front();
			if(L.r-1>0&&a[L.r-1][L.c]!=a[L.r][L.c]){
				L.r--;
				L.w_n++;
				Q.push(L);
				flag=true;
			}
			L=Q.front();
			if(L.r+1<=n&&a[L.r+1][L.c]!=a[L.r][L.c]){
				L.r++;
				L.w_n++;
				Q.push(L);
				flag=true;
			}
			if(!flag){
				maxx=max(maxx,L.w_n);
			}
			Q.pop();
		}
		cout<<maxx<<endl;
	}
	return 0;
}

P1141

2024/7/20 14:46
加载中...