拨钟问题

注意逻辑顺序
#include <cstdio>
#include <iostream>

using namespace std;
bool success(int* a)
{
	for (int i = 0; i < 9; i++)
	{
		if (a[i] != 0)
			return false;
	}
	return true;
}
int main()
{
	int clk[10];
	for (int i = 0; i < 9; i++)
		scanf("%d", &clk[i]);
	if (success(clk))
	{
		cout << '0' << endl;
		return 0;
	}
	int min = 10000;
	int count[9] = {};
	int a[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 p0, p1, p2, p3, p4, p5, p6, p7, p8;
	for ( p0 = 0; p0 < 4; p0++)
	for ( p1 = 0; p1 < 4; p1++)
	for ( p2 = 0; p2 < 4; p2++)
	for ( p3 = 0; p3 < 4; p3++)
	for ( p4 = 0; p4 < 4; p4++)
	for ( p5 = 0; p5 < 4; p5++)
	for ( p6 = 0; p6 < 4; p6++)
	for ( p7 = 0; p7 < 4; p7++)
	for ( p8 = 0; p8 < 4; p8++)
	{
		bool success = true;
		/*if (p2 == 1 && p4 == 1 && p6 == 1)
		{
			cout << "fuck!" << endl;
		}*/
		for (int i = 0; i < 9; i++)
		{
			if ((clk[i] + a[0][i] * p0 + a[1][i] * p1 + a[2][i] * p2 + a[3][i] * p3 +
				a[4][i] * p4 + a[5][i] * p5 + a[6][i] * p6 + a[7][i] * p7 + a[8][i] * p8) % 4 != 0)
			{
				success = false;
				break;
			}
		}
		if (success)
		{
			int num;
			num = p0 + p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8;
			if (num < min)
			{
				min = num;
				count[0] = p0; count[1] = p1; count[2] = p2;
				count[3] = p3; count[4] = p4; count[5] = p5;
				count[6] = p6; count[7] = p7; count[8] = p8;
			}
		}
	}
	//cout << p0 << " " << p1 << " " << p2 << " " << p3 << " " << p4 << " " << p5 << " " << p6 << " " << p7 << " " << p8 << endl;
	for (int i = 0; i < 9; i++)
	{
		while (count[i]--)
		{
			printf("%d ", i + 1);
		}
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值