USACO1.4.2--The Clocks
2013-01-21 11:59
399 查看
The Clocks
IOI'94 - Day 2
Consider nine clocks arranged in a 3x3 array thusly:
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.
[But this might or might not be the `correct' answer; see below.]
View Code
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 解题思路:DFS。每种方案最多选三次,因为旋转四次就恢复原状态了,相当于没进行操作。由于方案的顺序并不重要,因此满足要求就可以输出,中断搜索。 表示被一个BUG坑死了,整整坑了两天。仅仅因为把赋值符号“=”打成“==”了,然后就一直不输出结果,惨痛的教训啊,以后一定要记住!!!
View Code
#include <stdio.h> int a[9][9]= { {3,3,3,3,3,2,3,2,0}, {2,3,2,3,2,3,1,0,1}, {3,3,3,2,3,3,0,2,3}, {2,3,1,3,2,0,2,3,1}, {2,3,2,3,1,3,2,3,2}, {1,3,2,0,2,3,1,3,2}, {3,2,0,3,3,2,3,3,3}, {1,0,1,3,2,3,2,3,2}, {0,2,3,2,3,3,3,3,3} }; int v[9]; int main() { int i,j,k; freopen("clocks.in","r",stdin); for (i=0; i<9; i++) { scanf("%d",&k); for(j=0; j<9; j++) v[j]=(v[j]+(4-k/3)*a[i][j])%4; } fclose(stdin); k=0; freopen("clocks.out","w",stdout); for (i=0; i<9; i++) for (j=0; j<v[i]; j++) if (!k) { printf("%d",i+1); k=1; } else printf(" %d",i+1); printf("\n"); fclose(stdout); return 0; }
相关文章推荐
- USACO:1.4.2 The Clocks 时钟(IOI 94) 解析
- USACO section 1.4.2 The Clocks
- 1250. 【USACO题库】1.4.2 The Clocks (Standard IO)
- USACO 1.4.2 The Clocks
- USACO section 1.4.2 The Clocks
- [USACO 1.4.2] The Clocks
- 【USACO题库】1.4.2 The Clocks
- USACO1.4.2(The clocks)BFS
- USACO 1.4.2 The Clocks(DFS)
- Usaco 1.4.2 时钟(The Clocks)
- JZOJ1250.【USACO题库】1.4.2 The Clocks
- usaco1.4.2 Mother's Milk
- the clocks(usaco)
- USACO6.5.4 The Clocks(clocks)
- USACO:The Clocks
- USACO 1.4.2 BFS 解法。
- USACO 1.4.2 Mother's Milk
- USACO 1.41 The clocks
- 【宽搜】The Clocks 时钟 (Usaco_Training 1.4)
- USACO 1.4-The Clocks