#include<iostream> #include<string> using namespace std; int a[5][5];int b[5][5]; #define rep(i,j,k) for(int i=j;i<=k;i++) int n=4; string s[20]; void update(int i,int j) { b[i][j]=1-b[i][j]; b[i-1][j]=1-b[i-1][j]; b[i+1][j]=1-b[i+1][j]; b[i][j-1]=1-b[i][j-1]; b[i][j+1]=1-b[i][j+1]; } int judge(int x,int flag) { rep(i,1,n) rep(j,1,n) b[i][j]=a[i][j]; int sum=0; rep(i,1,n) { if(x%2) { update(1,i); sum++; } x/=2; } rep(i,1,n-1) rep(j,1,n) { if(b[i][j]==flag) { update(i+1,j); sum++; } } rep(i,1,n) if(b[n][i]==flag) return 300; return sum; } int main() { rep(i,1,n) { string tmp; cin>>tmp; s[i]=" "+tmp; } rep(i,1,n) { rep(j,1,n) if(s[i][j]==‘w‘) a[i][j]=0; else a[i][j]=1; } int maxnum=300; rep(i,0,(1<<n)-1) { maxnum=min(maxnum,judge(i,1)); maxnum=min(maxnum,judge(i,0)); } if(maxnum==300) cout<<"Impossible"; else cout<<maxnum; }
时间: 2024-10-13 05:41:29