Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
123863 | 柯昊阳 | 翻转棋盘 | C++ | 解答错误 | 20 | 16 MS | 252 KB | 867 | 2024-01-23 10:01:48 |
#include <bits/stdc++.h> using namespace std; bool flag,Map[6][6]; int dir[5][2] = {{-1,0},{1,0},{0,-1},{0,1},{0,0}}; int step; void Flip(int x,int y){ for(int i = 0;i<4;i++){ Map[x+dir[i][0]][y+dir[i][1]] = !Map[x+dir[i][0]][y+dir[i][1]]; } } bool OK(){ for(int i = 1;i<=4;i++){ for(int j = 1;j<=4;j++){ if(Map[i][j]^Map[1][1]) return false; } } return true; } void DFS(int x,int y,int dep){ if(dep==step){ flag = OK(); } if(flag||x==5){ return ; } Flip(x,y); if(y<4) DFS(x,y+1,dep+1); else DFS(x+1,1,dep+1); Flip(x,y); if(y<4) DFS(x,y+1,dep); else DFS(x+1,1,dep); } int main(){ char c; for(int i = 1;i<=4;i++){ for(int j = 1;j<=4;j++){ Map[i][j] = (cin>>c,c=='w'); } } for(step = 0;!flag&&step<=16;++step) DFS(1,1,0); flag?cout<<step-1<<endl:cout<<"Impossible"<<endl; return 0; }