听灌多
  • 板块灌水区
  • 楼主_AC_IS_GOD_QP_
  • 当前回复21
  • 已保存回复21
  • 发布时间2024/7/20 13:49
  • 上次更新2024/7/20 14:46:56
查看原帖
听灌多
744442
_AC_IS_GOD_QP_楼主2024/7/20 13:49

rt,P1141,输入不了起始坐标。。。

#include<bits/stdc++.h>
using namespace std;
struct node{
	int w_n,r,c;
};
int main(){
	int n,m;
	bool a[1005][1005];
	int maxx=-1e9;
	queue<node> Q;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			cin>>a[i][j];
		}
	}
	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;
}

求调

2024/7/20 13:49
加载中...