USACO The Clocks

操作间没有次序关系,同一个操作最多重复3次。。。

可以直接暴力。。。

 

The Clocks
IOI'94 - Day 2

Consider nine clocks arranged in a 3x3 array thusly:

|-------|    |-------|    |-------|    
|       |    |       |    |   |   |    
|---O   |    |---O   |    |   O   |          
|       |    |       |    |       |           
|-------|    |-------|    |-------|    
    A            B            C

|-------|    |-------|    |-------|
|       |    |       |    |       |
|   O   |    |   O   |    |   O   |
|   |   |    |   |   |    |   |   |
|-------|    |-------|    |-------|
    D            E            F

|-------|    |-------|    |-------|
|       |    |       |    |       |
|   O   |    |   O---|    |   O   |
|   |   |    |       |    |   |   |
|-------|    |-------|    |-------|
    G            H            I

 

The goal is to find a minimal sequence of moves to return all the dials to 12 o'clock. Nine different ways to turn the dials on the clocks are supplied via a table below; each way is called a move. Select for each move a number 1 through 9 which will cause the dials of the affected clocks (see next table) to be turned 90 degrees clockwise.

MoveAffected clocks
1ABDE
2ABC
3BCEF
4ADG
5BDEFH
6CFI
7DEGH
8GHI
9EFHI

Example

Each number represents a time according to following table:

9 9 12       9 12 12       9 12 12        12 12 12      12 12 12 
6 6 6  5 ->  9  9  9  8->  9  9  9  4 ->  12  9  9  9-> 12 12 12 
6 3 6        6  6  6       9  9  9        12  9  9      12 12 12 

[But this might or might not be the `correct' answer; see below.]

PROGRAM NAME: clocks

INPUT FORMAT

Lines 1-3:Three lines of three space-separated numbers; each number represents the start time of one clock, 3, 6, 9, or 12. The ordering of the numbers corresponds to the first example above.

SAMPLE INPUT (file clocks.in)

9 9 12
6 6 6
6 3 6

OUTPUT FORMAT

A single line that contains a space separated list of the shortest sequence of moves (designated by numbers) which returns all the clocks to 12:00. If there is more than one solution, print the one which gives the lowest number when the moves are concatenated (e.g., 5 2 4 6 < 9 3 1 1).

SAMPLE OUTPUT (file clocks.out)

4 5 8 9

 


Submission file Name:   
USACO Gateway  |    Comment or Question

 


 

/*
    ID:qhn9992
    PROG:clocks
    LANG:C++11
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int a[10],c[10];
int b[10][10]
={  0,0,0,0,0,0,0,0,0,0,
    1,1,0,1,1,0,0,0,0,0,
    1,1,1,0,0,0,0,0,0,0,
    0,1,1,0,1,1,0,0,0,0,
    1,0,0,1,0,0,1,0,0,0,
    0,1,0,1,1,1,0,1,0,0,
    0,0,1,0,0,1,0,0,1,0,
    0,0,0,1,1,0,1,1,0,0,
    0,0,0,0,0,0,1,1,1,0,
    0,0,0,0,1,1,0,1,1,0
};

int main()
{
    freopen("clocks.in","r",stdin);
    freopen("clocks.out","w",stdout);
	int cnt=0;

	for(int i=1;i<=9;i++)
	{
		scanf("%d",a+i);
		a[i]=(a[i]/3)%4;
	}
	for(c[1]=0;c[1]<4;c[1]++)
	{
		for(c[2]=0;c[2]<4;c[2]++)
		{
			for(c[3]=0;c[3]<4;c[3]++)
			{
				for(c[4]=0;c[4]<4;c[4]++)
				{
					for(c[5]=0;c[5]<4;c[5]++)
					{
						for(c[6]=0;c[6]<4;c[6]++)
						{
							for(c[7]=0;c[7]<4;c[7]++)
							{
								for(c[8]=0;c[8]<4;c[8]++)
								{
									for(c[9]=0;c[9]<4;c[9]++)
									{
										///check....
										bool flag=true;
										for(int i=1;i<=9;i++)
										{
											int t=a[i];
											for(int j=1;j<=9;j++)
											{
												t+=b[j][i-1]*c[j];
											}
											t=t%4;
											if(t)
											{
												flag=false;
												break;
											}
										}
										if(flag)
										{
											for(int i=1;i<=9;i++)
											{
												while(c[i]--)
												{
													if(flag)
													{
														flag=false;
													}
													else putchar(32);
													printf("%d",i);
												}
											}
											putchar(10);
											return 0;
										}
										else continue;
									}
								}
							}
						}
					}
				}
			}
		}
	}
    return 0;
}


 


 

转载于:https://www.cnblogs.com/fuhaots2009/p/3508708.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值