USACO 1.4 The Clocks (暴力枚举)
2015-09-19 17:51
405 查看
#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 DEBUG int 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); #endif int 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 } #endif return 0; }
相关文章推荐
- USACO 3.2.2:Stringsobits
- USACO 3.1 Shaping Regions
- 【解题报告】【USACO】酸奶工厂
- usaco-Calf Flac
- usaco/1.1 Your Ride Is Here
- usaco/1.1 Greedy Gift Givers
- usaco/1.1 Friday the Thirteenth
- usaco/ 1.1 Broken Necklace
- USACO/fact4 3.2.1
- USACO/spin 3.2.3
- USACO/rockers 3.4.4 动态规划
- USACO 2.2 Party Lamps
- USACO 2.2 Runaround Numbers
- USACO 2.2 Subset Numbers
- USACO 2.2 Preface Numbering
- USACO 2.1 Ordered Fractions
- USACO 2.1 Hamming Codes
- USACO 2.1 Healthy Holsteins
- USACO 2.1 Sorting A Three-Valued Sequence
- USACO 2.1 The Castle