Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
123923 | 刘子涵 | 翻转棋盘 | C++ | 通过 | 100 | 1 MS | 240 KB | 769 | 2024-01-23 10:14:15 |
#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; }