USACO 1.4 The Clocks (暴力枚举)

来源:互联网 发布:银背大猩猩战斗力知乎 编辑:程序博客网 时间:2024/05/16 09:56
#include <stdio.h>#define DEBUG 0#define TESTCASES 9#define CLOCKS 9#define MOVES 9#define FOR(index, size) for ((index) = 0; (index) < (size); (index)++)int initialState[CLOCKS];int arrayOfMove[MOVES][CLOCKS] = { {3, 3, 0, 3, 3, 0, 0, 0, 0},    {3, 3, 3, 0, 0, 0, 0, 0, 0},    {0, 3, 3, 0, 3, 3, 0, 0, 0},                                {3, 0, 0, 3, 0, 0, 3, 0, 0},    {0, 3, 0, 3, 3, 3, 0, 3, 0},    {0, 0, 3, 0, 0, 3, 0, 0, 3},    {0, 0, 0, 3, 3, 0, 3, 3, 0},{0, 0, 0, 0, 0, 0, 3, 3, 3},                                {0, 0, 0, 0, 3, 3, 0, 3, 3} };int timesOfMove[MOVES];int main(){#if DEBUGint testCase;for (testCase = 1; testCase <= TESTCASES; testCase++){char inputFileName[20] = "inputX.txt";inputFileName[5] = '1' +  (testCase - 1);freopen(inputFileName, "r", stdin);printf("\n#%d\n", testCase);#endifint clock;FOR(clock, CLOCKS)scanf("%d", &initialState[clock]);int state;FOR(timesOfMove[0], 4)FOR(timesOfMove[1], 4)FOR(timesOfMove[2], 4)FOR(timesOfMove[3], 4)FOR(timesOfMove[4], 4)FOR(timesOfMove[5], 4)FOR(timesOfMove[6], 4)FOR(timesOfMove[7], 4)FOR(timesOfMove[8], 4){int fail = 0;FOR(clock, CLOCKS){state = initialState[clock];int move;FOR(move, MOVES)state += arrayOfMove[move][clock] * timesOfMove[move];if (state % 12 != 0){fail = 1;break;}}//end of FOR(clock, CLOCKS)if (fail == 0){int move;FOR(move, MOVES){int times = timesOfMove[move];while (times >  0){printf("%d%c", move + 1, move == MOVES - 1 && times == 1 ? '\n' : ' ');times--;}}}}//end of FOR(timesOfMove[8], 4)#if DEBUG}#endifreturn 0;}

0 0
原创粉丝点击