提交时间:2024-01-23 10:14:15
运行 ID: 123923
#include<bits/stdc++.h> using namespace std; char t[6][6]; int ans=1e9; bool p[6][6]; void dfs(int x,int y,int c){ if(c>ans) return; if(y>4) y=1,x++; if(x>4){ for(int i=1;i<=4;i++){ for(int j=1;j<=4;j++) if(p[i][j]!=p[1][1]) return; } ans=min(ans,c); return; } p[x][y]=!p[x][y]; p[x+1][y]=!p[x+1][y]; p[x-1][y]=!p[x-1][y]; p[x][y+1]=!p[x][y+1]; p[x][y-1]=!p[x][y-1]; dfs(x,y+1,c+1); p[x][y]=!p[x][y]; p[x+1][y]=!p[x+1][y]; p[x-1][y]=!p[x-1][y]; p[x][y+1]=!p[x][y+1]; p[x][y-1]=!p[x][y-1]; dfs(x,y+1,c); } int main(){ for(int i=1;i<=4;i++) cin>>t[i]+1; for(int i=1;i<=4;i++) for(int j=1;j<=4;j++) p[i][j]=t[i][j]=='b'?true:false; dfs(1,1,0); if(ans==1e9) cout<<"Impossible"; else cout<<ans; return 0; }