Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
开心#include<cstdio> #include<iostream> using namespace std; int f[9]={0}; int a[9]={9}; int flag; int m[9][9] ={ {1,1,0,1,1,0,0,0,0}, {1,1,1,0,0,0,0,0,0}, {0,1,1,0,1,1,0,0,0}, {1,0,0,1,0,0,1,0,0}, {0,1,0,1,1,1,0,1,0}, {0,0,1,0,0,1,0,0,1}, {0,0,0,1,1,0,1,1,0}, {0,0,0,0,0,0,1,1,1}, {0,0,0,0,1,1,0,1,1}}; void out() { for (int i = 0; i<9; i++) for (int j = 0; j < f[i];j++) printf("%d ",i+1); printf("\n"); } int tmp[9] = {0}; int judge() { int i,j; for (i = 0; i < 9; i++) { tmp[i] = a[i]; //cout<<tmp[i]<<' '; for (j = 0; j < 9; j++) { tmp[i]+=f[j]*m[j][i]; } if (tmp[i] % 4) break; } //cout<<i<<endl; if (i == 9) { flag = 0; return 1;//!! } return 0;//!! } void dfs(int n) { if (n == 9) { if ( judge()) { flag = 0; out(); return; } return; } if (flag) { for (int i = 0; i<4; i++) { f[n] = i; dfs(n+1); if (flag == 0) return; f[n] = 0; } } } int main() { //freopen("1166.txt","r",stdin); for (int i = 0; i<9; i++) scanf("%d",&a[i]); flag = 1; dfs(0); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator