HDU5547
我的错误代码:待修改中
#include<iostream> #include<vector> #include<cmath> #include<cstring> using namespace std; char mp[5][5]; int num[5][5]; vector<int> vec; bool judge(){ for(int i=0;i<4;i++) { if((num[i][0]+num[i][1]+num[i][2]+num[i][3]==49) && (num[0][i]+num[1][i]+num[2][i]+num[3][i]==49))continue; else return false; } int t[4][2] = {{0,0},{0,2},{2,0},{2,2}}; for(int i=0;i<4;i++) { int x = t[i][0]; int y = t[i][1]; if(num[x][y]+num[x+1][y]+num[x][y+1]+num[x+1][y+1]==49) continue; else return false; } return true; } void solve(int step){ if(step==vec.size()){ if(judge()){ for(int i=0;i<4;i++){ for(int j=0;j<4;j++) cout<<mp[i][j]; cout<<endl; } } return; } for(int i=1;i<=4;i++){ bool same = false; int t = vec[step]; int r=t/4, c=t%4; for(int j=0;j<4;j++){ if((int)mp[r][j]-'0'==i||(int)mp[j][c]-'0'==i){same=true;break;} } if(same) continue; mp[r][c] = (char)('0'+i); num[r][c] = i*pow(2,i-1); solve(step+1); } } int main() { int t,cas = 1; cin>>t; while(t--){ memset(num,0,sizeof(0));vec.clear(); for(int i=0;i<4;i++){ for(int j=0;j<4;j++){ cin>>mp[i][j]; if(mp[i][j]=='*'){ vec.push_back(i*4+j); }else{ num[i][j] = ((int)mp[i][j]-'0')*pow(2,(double)mp[i][j]-'0'-1); } } } printf("Case #%d:\n",cas++); solve(0); } return 0; }