您的位置:首页 > 其它

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 1.4 The Clocks