2014牡丹江网络预选赛F题(隐式图BFS暴搜)zoj3814
2014-09-11 00:37
459 查看
Sawtooth Puzzle
Time Limit: 10 Seconds Memory Limit: 65536 KB
Recently, you found an interesting game called Sawtooth Puzzle. This is a single-player game played on a grid with 3 x 3 cells. Each cell contains a part of an image. Besides,
each edge of a cell will be either smooth or saw-toothed. Two edge-adjacent cells are considered as meshed if their adjacent edges are both saw-toothed.
The game contains zero or more steps. At each step, the player can choose one cell, rotate it by 90 degrees clockwise. At the beginning of rotation, any cell which is going to rotate
will drive other cells to rotate together if they are meshed. Of course, the driven (passive) cell will rotate in the opposite direction against the driver (active) cell. The following image demonstrates the procedure of rotating the middle cell clockwise:
Given the initial image and target image of the puzzle, please find out the minimum number of steps needed to solve it.
The input data consists of three parts. The first part represents the initial image of the puzzle. It contains 26 lines. Each line has 26 characters (excluding the line break '\n'). The
image is composed of 3 x 3 cells. Each cell is a monochrome image of 8 x 8 pixels ('#' for black, '.' for white). These cells are separated by space characters of 1 pixel width.
The second part represents the target image of the puzzle. It has the same format as which described above.
The last part contains 9 lines. Each line has 4 integers indicating the edge type (0 for smooth, 1 for saw-toothed) of a cell. The cells are listed in the order of top-left, top-middle,
top-right, middle-left, ... , till bottom-right. For each cell, the edge type are given in the order of left, top, right and bottom.
There is an empty line between any two adjacent parts (including of different cases).
题意:RT
思路:BFS暴搜
注意以下几点即可:
1.每次扩展状态的时候要对9个方块分别右旋
2.终点的状态可能有很多个,因为有的格子旋转以后的图案还是和之前一样
3.处理的时候注意一下细节即可(这个把我坑了好久,比如我在旋转第3个块的时候把它左边的块也旋转了,实际上它的左边是没有块的)
Time Limit: 10 Seconds Memory Limit: 65536 KB
Recently, you found an interesting game called Sawtooth Puzzle. This is a single-player game played on a grid with 3 x 3 cells. Each cell contains a part of an image. Besides,
each edge of a cell will be either smooth or saw-toothed. Two edge-adjacent cells are considered as meshed if their adjacent edges are both saw-toothed.
The game contains zero or more steps. At each step, the player can choose one cell, rotate it by 90 degrees clockwise. At the beginning of rotation, any cell which is going to rotate
will drive other cells to rotate together if they are meshed. Of course, the driven (passive) cell will rotate in the opposite direction against the driver (active) cell. The following image demonstrates the procedure of rotating the middle cell clockwise:
Given the initial image and target image of the puzzle, please find out the minimum number of steps needed to solve it.
Input
There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:The input data consists of three parts. The first part represents the initial image of the puzzle. It contains 26 lines. Each line has 26 characters (excluding the line break '\n'). The
image is composed of 3 x 3 cells. Each cell is a monochrome image of 8 x 8 pixels ('#' for black, '.' for white). These cells are separated by space characters of 1 pixel width.
The second part represents the target image of the puzzle. It has the same format as which described above.
The last part contains 9 lines. Each line has 4 integers indicating the edge type (0 for smooth, 1 for saw-toothed) of a cell. The cells are listed in the order of top-left, top-middle,
top-right, middle-left, ... , till bottom-right. For each cell, the edge type are given in the order of left, top, right and bottom.
There is an empty line between any two adjacent parts (including of different cases).
Output
For each test case, output the minimum number of steps needed to solve the puzzle. If there is no solution, output -1 instead.Sample Input
1 ......#. ........ ........ ......## ........ ........ .......# #....... ........ .......# ##...... ...##... .......# ###..... .###.... .......# ####...# ####.... .......# ######## ###..... .......# ######## ###..... ........ ######## ###..... .......# ######## ##...... .....### ######## ##...... ....#### ######## ###..... ..###### ######## ####.... ######## ######## #####... ...##### ######## ######.. ........ ######## #######. ........ ........ ..###### ........ .....### ........ ........ ######## ........ ........ .####### ........ ........ ...##### ........ ........ .....### ........ ........ .......# ........ ........ ........ ........ ......#. ........ ........ ......## ........ ........ .......# #....... ........ .......# ##...... ...##... .......# ###..... .###.... .......# ####...# ####.... .......# ######## ###..... .......# ######## ###..... ........ ######## ###..... .......# ######## ##...... .....### ######## ##...... ....#### ######## ###..... ..###### ######## ####.... ######## ######## #####... ...##### ######## ######.. ........ ######## #######. ........ .######. ..###### ........ .#####.. ........ ........ .#####.. ........ ........ ..###... ........ ........ ..###... ........ ........ ..##.... ........ ........ ..##.... ........ ........ ..#..... ........ 0 1 0 1 0 0 1 1 1 0 0 1 0 0 1 1 1 1 1 0 1 0 1 1 1 1 1 1 0 0 1 0 0 1 1 0
Sample Output
6
题意:RT
思路:BFS暴搜
注意以下几点即可:
1.每次扩展状态的时候要对9个方块分别右旋
2.终点的状态可能有很多个,因为有的格子旋转以后的图案还是和之前一样
3.处理的时候注意一下细节即可(这个把我坑了好久,比如我在旋转第3个块的时候把它左边的块也旋转了,实际上它的左边是没有块的)
相关文章推荐
- ZOJ 3809 The Himalayas (2014 ACM/ICPC 牡丹江站 网络预选赛 A 题)
- 2014牡丹江网络预选赛B题(找规律)zoj3810
- ZOJ 3818 The Himalayas (2014 ACM/ICPC 牡丹江站 网络预选赛 J 题)
- 2014牡丹江网络预选赛I题(字符串hash+简单DP)zoj3817
- ZOJ 3814 / 2014 牡丹江赛区网络赛 F. Sawtooth Puzzle
- ZOJ 3811 / 2014 牡丹江赛区网络赛 C. Untrusted Patrol bfs/dfs/并查集
- ZOJ 3814 Sawtooth Puzzle (2014年牡丹江赛区网络赛F题)
- zoj 3813 Alternating Sum(2014ACMICPC Regional 牡丹江站网络赛 E)
- ZOJ 3814 Sawtooth Puzzle (2014年牡丹江赛区网络赛F题)
- [ACM] zoj 3809 The Himalayas (2014 ACMICPC Regional 牡丹江站网络赛 A题)
- zoj 3813 Alternating Sum(2014ACMICPC Regional 牡丹江站网络赛 E)
- 2014牡丹江网络zoj3816Generalized Palindromic Number(dfs或者bfs)
- ZOJ 3812 We Need Medicine(dp,状态压缩,2014牡丹江网络赛D题)
- 2014牡丹江网络预选赛D题(状压DP)zoj3812
- 2014牡丹江网络赛ZOJPretty Poem(暴力枚举)
- ZOJ 3811 / 2014 牡丹江赛区网络赛 C. Untrusted Patrol
- zoj 3811 Untrusted Patrol 2014牡丹江网络赛 dfs
- ZOJ 3814 Sawtooth Puzzle(牡丹江网络赛F题)
- [ACM] zoj 3818 Pretty Poem (2014 ACMICPC Regional 牡丹江站网络赛 J题)
- zoj 3813 Alternating Sum(2014ACMICPC Regional 牡丹江站网络赛 E)