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 |
此代码绝非show,意在抛砖引玉^_^#include <iostream> #include <string.h> #include <stdlib.h> using namespace std; const int cmd[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}// }; int x[9], a[9]; bool ok() { int tmp[9]; for(int i = 0; i < 9; i++) tmp[i] = a[i]; for(int j = 0; j < 9; j++) for(int i = 0; i < 9; i++) tmp[j] = (tmp[j] + cmd[i][j] * x[i]) % 4; for(int i = 0; i < 9; i++) if(tmp[i] != 0) return 0; return 1; } void print() { for(int i = 0; i < 9; i++) for(int j = 0; j < x[i]; j++) printf("%d ", i + 1); printf("\n"); } int main() { for(int i = 0; i < 9; i++) cin >> a[i]; memset(x, -1, sizeof(x)); int k = 0; while(k >= 0) { x[k] += 1; if(x[k] <= 3) { if(k == 8 && ok()) { print(); break; } else if(k < 8) k++; } else { x[k] = -1; k--; } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator