玄关 求调
查看原帖
玄关 求调
1042427
IOI_winner楼主2025/1/8 20:21

玄关 求调

#include <bits/stdc++.h>
using namespace std;
bool g[10][10],bg[10][10];
int t;
int ydx[10]= {0,-1,1,0,0},ydy[10]= {0,0,0,-1,1};

int fck(int x,int y) {
	for(int i=0; i<=4; i++)
		if(x+ydx[i]>=1&&x+ydx[i]<=5&&y+ydy[i]>=1&&y+ydy[i]<=5)
			g[x+ydx[i]][y+ydy[i]]=(g[x+ydx[i]][y+ydy[i]]+1)%2;
}
int main() {
	cin>>t;
	for(int i=1; i<=t; i++) {
		for(int a=1; a<=5; a++)
			for(int b=1; b<=5; b++) {
				char n;
				cin>>n;
				bg[a][b]=int(n-'0');
			}
		bool pd=1;
		for(int j=0; j<32; j++) {
			memcpy(g,bg,sizeof g);
			int m=j;
			int cnt=0;
			for(int a=1; a<=5; a++) {
				if(m&1) {fck(1,a);cnt++;}
				m>>=1;
			}
			bool flag=1;
			for(int a=1; a<=4; a++) {
				for(int b=1; b<=5; b++) {
					if(g[a][b]==0) {
						fck(a+1,b);
						cnt++;
					}
					if(cnt>6) {
						flag=0;
						break;
					}
				}
				if(flag==0) break;
			}
			for(int a=1; a<=5; a++)
				if(g[5][a]==0) {
					flag=0;
					break;
				}
			if(flag==1) {
				cout<<cnt<<endl;
				pd=0;
				break;
			}
		}
		if(pd==1) cout<<-1<<endl;
	}
}

acwing上过了,为啥洛谷RE了呀。RE链接

2025/1/8 20:21
加载中...