编程介的小学生 2017-09-18 03:57 采纳率: 20.5%
浏览 773
已采纳

Another Puzzling Problem

You are to write a program to solve jigsaw puzzles. The input file will contain the dimension of the puzzle, the dimension of the pieces, and the actual pieces of the puzzle. The pieces will be made up of ASCII characters. You are to create an output file which consists of the solved puzzle.

Input

The first line of the input file will contain three integers. These are the dimension of the puzzle (puzzles are always square), and the height and width of the pieces, respectively. The dimension of the puzzle can range from 2 to 10, and the height and width of each puzzle piece can range from 1 to 25. For example, the input "2 2 3" (without the quotes, of course) specifies a puzzle that is 2 * 2 pieces in size, with individual pieces that are 2 * 3 characters in size. All pieces have the same height and width.

The rest of the file specifies the puzzle pieces in arbitrary order. Each piece is specified by an image of the piece followed by a line containing four integers ranging from -5 to +5. These values indicate the shape of the top, left, bottom and right edges of the puzzle piece, respectively. Values of 0 identify straight (i.e. outer) edges. Positive and negative edges of the same value are pairs that interlock (e.g. -5 interlocks with +5, -4 with +4, etc.). Puzzle pieces may not be rotated, and all pieces will be unique (that is, no two pieces will have the same values for all four edges). A blank line separates each puzzle piece.

The input contains multiple cases, process to the end of file.

Output

Note that spaces (ASCII character 32) are valid characters in a puzzle piece. If they appear at the end of a line (or are the only characters on a line), then they will appear in the input file. All pieces will be a rectangular block of characters (ASCII codes 32 to 127), even if spaces at the end of a line make it appear differently. In short, spaces should be treated no differently than any other character.

The output file should simply contain the solved puzzle in the proper arrangement. The input puzzle will have one and only one solution.

Sample Input

2 2 3
OOC
BCC
-2 2 0 0

AOO
AAB
5 0 0 -2

XXY
XOO
0 0 -5 -5

YZZ
OOZ
0 5 2 0

2 8 14
88,

8888.

:8888b

8888

-.:888b

' d8888

,88888

':88888

0 3 -1 0

     o8%88
   o88%888
  8'-    -
 8'       
d8.-=. ,==
>8 `~` :`~
88        
88b. `-~  

0 0 -5 -3

.:88888

:::8888

:' 8888b

8888b

,%888b.

%%%8--'-.
_%-' --- -
.-' = --.

1 4 0 0

888b ~==~ 
88888o--:'
`88888| ::
8888^^'   

d888

d88%

/88:.__ ,

'''::===.
5 0 0 -4

Sample Output

XXYYZZ
XOOOOZ
AOOOOC
AABBCC
o8%8888,

o88%8888888.

8'- -:8888b

8' 8888

d8.-=. ,==-.:888b

>8 ~ :~' d8888
88 ,88888
88b.
-~ ':88888

888b ~==~ .:88888

88888o--:':::8888

`88888| :::' 8888b

8888^^' 8888b

d888 ,%888b.

d88% %%%8--'-.
/88:.__ , _%-' --- -
'''::===..-' = --.

  • 写回答

1条回答

  • threenewbee 2017-10-02 15:47
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 虚心请教几个问题,小生先有礼了
  • ¥30 截图中的mathematics程序转换成matlab