Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
124708 林扬泉 翻转棋盘 C++ 通过 100 1 MS 252 KB 808 2024-01-23 15:28:27

Tests(25/25):


#include<bits/stdc++.h> using namespace std; int f[17]; int res=0x3f3f3f3f; void ch(int pos){ int x=pos/4; int y=pos%4; f[pos]=!f[pos]; if(x>0){ f[pos-4]=!f[pos-4]; } if(x<3){ f[pos+4]=!f[pos+4]; } if(y>0){ f[pos-1]=!f[pos-1]; } if(y<3){ f[pos+1]=!f[pos+1]; } } bool pd(){ for(int i=0;i<15;i++){ if(f[i]!=f[i+1]){ return false; } } return true; } void dfs(int cur,int cnt){ if(pd()){ if(cnt<res){ res=cnt; return; } } if(cur>=16){ return; } ch(cur); dfs(cur+1,cnt+1); ch(cur); dfs(cur+1,cnt); return; } int main(){ char x; for(int i=0;i<16;i++){ cin>>x; if(x=='b'){ f[i]=1; } } dfs(0,0); if(res==0x3f3f3f3f){ printf("Impossible\n"); } else{ printf("%d\n",res); } return 0; }


测评信息: