1.4 clocks 枚举

本文介绍了一个经典的算法问题——九个钟表通过特定操作全部调整至12点位置的方法。采用枚举策略,考虑每个操作最多执行三次,通过遍历所有可能组合找出最短的操作序列。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

注意转变思路,每个操作最多执行三次,所有解空间是4**9个,枚举所有可能的操作

钟表a受影响的操作有1,3,4

用上述方法,判断每个操作后的状态

输出即可

 

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.
Move     Affected clocks
1     ABDE
2     ABC
3     BCEF
4     ADG
5     BDEFH
6     CFI
7     DEGH
8     GHI
9     EFHI
Example
Each number represents a time accoring 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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值