USACO 1.4 The Clocks (暴力枚举)

#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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值