POJ 1166 The Clocks

来源:互联网 发布:php留言板源代码 编辑:程序博客网 时间:2024/06/05 23:42
The Clocks
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 9161 Accepted: 3564

Description

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

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

|-------| |-------| |-------|
| | | | | |
| O | | O---| | O |
| | | | | | | |
|-------| |-------| |-------|
G H I
(Figure 1)

There are nine clocks in a 3*3 array (figure 1). The goal is to return all the dials to 12 o'clock with as few moves as possible. There are nine different allowed ways to turn the dials on the clocks. Each such way is called a move. Select for each move a number 1 to 9. That number will turn the dials 90' (degrees) clockwise on those clocks which are affected according to figure 2 below.
Move   Affected clocks

1 ABDE
2 ABC
3 BCEF
4 ADG
5 BDEFH
6 CFI
7 DEGH
8 GHI
9 EFHI
(Figure 2)

Input

Your program is to read from standard input. Nine numbers give the start positions of the dials. 0=12 o'clock, 1=3 o'clock, 2=6 o'clock, 3=9 o'clock.

Output

Your program is to write to standard output. Output a shortest sorted sequence of moves (numbers), which returns all the dials to 12 o'clock. You are convinced that the answer is unique.

Sample Input

3 3 02 2 22 1 2

Sample Output

4 5 8 9

Source

IOI 1994
 
 
题目大意:已知九个钟分别指向3 6 9 12    有九种操作 分别可以把几个钟顺时针转90°   问最少的把其都变成12点的步骤
题目分析:BFS   写了半天写迷糊了。。。   其实就是没种操作最多3次嘛   干脆9个循环!!! 
代码如下:
 
原创粉丝点击