poj3322翻译

来源:互联网 发布:java金融系统开发实例 编辑:程序博客网 时间:2024/06/06 12:34


1.Poj3322:Bloxorz1

Little Tom loves playing games. One day hedownloads a little computer game called 'Bloxorz' which makes him excited. It'sa game about rolling a box to a specific position on a special plane.Precisely, the plane, which is composed of several unit cells, is a rectangleshaped area. And the box, consisting of two perfectly aligned unit cube, mayeither lies down and occupies two neighbouring cells or stands up and occupiesone single cell. One may move the box by picking one of the four edges of thebox on the ground and rolling the box 90 degrees around that edge, which iscounted as one move. There are three kinds of cells, rigid cells, easily brokencells and empty cells. A rigid cell can support full weight of the box, so itcan be either one of the two cells that the box lies on or the cell that thebox fully stands on. A easily broken cells can only support half the weight ofthe box, so it cannot be the only cell that the box stands on. An empty cellcannot support anything, so there cannot be any part of the box on that cell.The target of the game is to roll the box standing onto the only target cell onthe plane with minimum moves.


The box stands on a single cell


The box lies on two neighbouring cells, horizontally


The box lies on two neighbouring cells, vertically

After Little Tom passes several stages ofthe game, he finds it much harder than he expected. So he turns to your help.

Input

Input contains multiple test cases. Eachtest case is one single stage of the game. It starts with two integers R and C(3≤ R, C ≤ 500) which stands for number of rows and columns of the plane. That followsthe plane, which contains R lines and C charactersfor each line, with 'O' (Oh) for target cell, 'X' for initial position of thebox, '.' for a rigid cell, '#' for a empty cell and 'E' for a easily brokencell. A test cases starts with two zeros ends the input.

It guarantees that

  • There's only one 'O' in a plane.
  • There's either one 'X' or neighbouring two 'X's in a plane.
  • The first(and last) row(and column) must be '#'(empty cell).
  • Cells covered by 'O' and 'X' are all rigid cells.

Output

For each test cases output one line withthe minimum number of moves or "Impossible" (without quote) whenthere's no way to achieve the target cell.  

Sample Input

7 7

#######

#..X###

#..##O#

#....E#

#....E#

#.....#

#######

0 0

Sample Output

10

Source

POJMonthly--2007.08.05, Rainer



 

 

 

 

 

 

翻译:

Poj3322

题目描述:

我们可爱的小汤姆喜欢玩游戏。最近让他下载了一款令他非常兴奋的小游戏叫做“Bloxorz”。这个游戏是关于将一个滚动的箱子翻动到一个平面上的某个具体的位置。恰好,这个平面是由许多小格子组成的一块矩形区域。这个箱子是由两个小正方体拼接而成。它可以躺在两个相邻的格子上,也可以站在一个格子上(温馨提示:躺的时候高为1,站的时候高为2)。汤姆可以通过围绕这个箱子的一条棱旋转90度来移动这个箱子,这样算作一次移动。在这个平面中,有三种格子:坚固的格子,和易碎的红格子以及空格子。一个坚固的格子可以承载这个箱子的全部重量,所以它和任意一个格子组合都可以承载这个箱子的所有重量(温馨提示:与空格子也可以)。但一个易碎的格子只能承载这个箱子一半的重量,所以这个易碎的格子不能单独承担整个箱子的重量(否则,咳咳,就掉下无底深渊了)。而一个空格子不能承担任何重量,所以它不能让箱子的任意部分呆在上面。(咳咳,否则也会掉进无底深渊。。。)

这游戏的目的就是用最小的步数滚动这个箱子到达目的格子。(当然不能掉下去了哈)


箱子站在一个箱子上


箱子水平地躺在两个相邻的格子上


箱子垂直地躺在两个垂直地格子上

输入格式:

输入包含多重测试数据。每个测试数据都是一个游戏棋盘。首先输入两个整数RC3 ≤ R, C ≤ 500),分别为这个游戏棋盘的行和列。在这个平面中,有RC列的字符。在其中,’O’代表目的地,’X’代表箱子现在的位置,’.’代表一个坚固的格子,’#’代表空格子,’E’代表一个易碎的格子。测试数据以两个0结尾。

该测试数据保证:

·只有一个’O’在平面中

·只会有一个或两个相邻的’X’在平面中

·边缘上的格子必定是’#’(空格子)

·’O’’X’代表的格子必为坚固的格子

输出格式:

对于每组测试数据,输出的必定是最小移动步数或者是’Impossible’(当没有方法去到达目的地的格子时)。

输入示例:

7 7

#######

#..X###

#..##O#

#....E#

#....E#

#.....#

#######

0 0

输出示例:

10

备注:

每月POJ2007.08.05Rainer原创

翻译:ysmor


0 0