22853_JerryMouse

2022-5-16 18:23| 发布者: Hocassian| 查看: 26| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-5-8950719340699-Problem List-采集的数据-后羿采集器.html

Pro.ID

22853

Title

Jerry Mouse

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=22853

AC

0

Submit

0

Ratio

-

时间&空间限制

  • Time Limit: 1000/500 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    Kudo and Saya are good friends, and they are always together.

    But today, since Saya is not here (Where is Saya? You can get the answer at Problem 22849), Kudo fells very bored. So Kudo starts to watch TV for fun.

    Now, she is watching the famous cartoon "Tom and Jerry". Jerry's home have many entrance, he always enter his home in an entrance and get out from another.

    Kudo suddenly thought that what will happen if there are many Jerrys?

    Kudo finds out a paper box and dig many holes in the side of the box. Then, she marks every hole with an integer, representing its owner. Finally, she signs the box "Kudo's House" as shown in Figure 1.

    Figure 1 The gray part represents a hole, and the numbers means its owner, i.e. the two gray parts in the lower left corner means the two holes belongs to mouse 2.

    Kudo think it is very interesting, so she makes a lot of boxes, and sign them "Saya's House", "Riki's House", "Lin's House" and so on.

    Figure 2 The jointed gray parts represent the same hole.

    At last, she combines them together to make a large box as shown in Figure 2.

    She defined mouse A and mouse B is the same mouse if and only if:

    a) mouse A and mouse B are in a same house and A equals to B;

    b) mouse A and mouse B are in different houses, but they have a hole that combined together, such as mouse 3 in Kudo's House and mouse 7 in Lin's House;

    c) There exits a lists of mouse M1, M2Mp, while A and M1 are the same, M1 and M2 are the same … Mp and B are the same.

    But there is a problem: Suppose mouse 3 in Kudo's House is the same with mouse 7 in Lin's House, while mouse 7 in Lin's House is the same with mouse 4 in Kudo's House. It means that mouse 3 and 4 in Kudo's House are the same!

    Kudo is very confused, so she comes to you for help.

    Given the initial N boxes, can you tell her finally each hole belongs to whom?

    Here, N always equals to 1, 4, 9, 16, 25, 36, 49, 64, 81 or 100. Kudo always combines the boxes as shownin Figure 3, while n=sqrt(N).

    Figure 3 How Kudo combines the boxes.

    输入

    The input consists of several test cases.

    The first line of input in each test case contains two integers N ( 0 < N ≤ 100 ) and M ( 0 < M ≤ 1000 ), which represent the number of boxes and the number of holes in each side of the box. In every side of the N boxes, You can assume that there are always M holes, and the M holes are arranged with equal spacing.

    Each of the next N lines containing 4M integers representing the holes on the boxes. The first M integers represent the holes on the upside, from left to right; the second M integers represent the holes on the downside, from left to right; the third M integers represent the holes on the leftward, from up to down; the forth M integers represent the holes on the rightward, from up to down. You can assume that the hole number is not greater than M*2.

    The last case is followed by a line containing two zeros.

    输出

    Description

    Kudo and Saya are good friends, and they are always together.

    But today, since Saya is not here (Where is Saya? You can get the answer at Problem 22849), Kudo fells very bored. So Kudo starts to watch TV for fun.

    Now, she is watching the famous cartoon "Tom and Jerry". Jerry's home have many entrance, he always enter his home in an entrance and get out from another.

    Kudo suddenly thought that what will happen if there are many Jerrys?

    Kudo finds out a paper box and dig many holes in the side of the box. Then, she marks every hole with an integer, representing its owner. Finally, she signs the box "Kudo's House" as shown in Figure 1.

    Figure 1 The gray part represents a hole, and the numbers means its owner, i.e. the two gray parts in the lower left corner means the two holes belongs to mouse 2.

    Kudo think it is very interesting, so she makes a lot of boxes, and sign them "Saya's House", "Riki's House", "Lin's House" and so on.

    Figure 2 The jointed gray parts represent the same hole.

    At last, she combines them together to make a large box as shown in Figure 2.

    She defined mouse A and mouse B is the same mouse if and only if:

    a) mouse A and mouse B are in a same house and A equals to B;

    b) mouse A and mouse B are in different houses, but they have a hole that combined together, such as mouse 3 in Kudo's House and mouse 7 in Lin's House;

    c) There exits a lists of mouse M1, M2Mp, while A and M1 are the same, M1 and M2 are the same … Mp and B are the same.

    But there is a problem: Suppose mouse 3 in Kudo's House is the same with mouse 7 in Lin's House, while mouse 7 in Lin's House is the same with mouse 4 in Kudo's House. It means that mouse 3 and 4 in Kudo's House are the same!

    Kudo is very confused, so she comes to you for help.

    Given the initial N boxes, can you tell her finally each hole belongs to whom?

    Here, N always equals to 1, 4, 9, 16, 25, 36, 49, 64, 81 or 100. Kudo always combines the boxes as shownin Figure 3, while n=sqrt(N).

    Figure 3 How Kudo combines the boxes.

    Input

    The input consists of several test cases.

    The first line of input in each test case contains two integers N ( 0 < N ≤ 100 ) and M ( 0 < M ≤ 1000 ), which represent the number of boxes and the number of holes in each side of the box. In every side of the N boxes, You can assume that there are always M holes, and the M holes are arranged with equal spacing.

    Each of the next N lines containing 4M integers representing the holes on the boxes. The first M integers represent the holes on the upside, from left to right; the second M integers represent the holes on the downside, from left to right; the third M integers represent the holes on the leftward, from up to down; the forth M integers represent the holes on the rightward, from up to down. You can assume that the hole number is not greater than M*2.

    The last case is followed by a line containing two zeros.

    Output

    For each case, print the case number (1, 2 …) and 4*n*M integers ( n = sqrt( N ) ) represents the holes on the upside, downside, leftward and rightward side of the large box, using the same format as the input file.

    In your answer, the holes signed by the same numbers should belong to the same mouse, while the holes signed by different numbers should belong to different mouse. The number should be an integer, starting from 1. Since there are multiply solutions, please print the one whose first number is the least. If there are still multiply solutions, print the one whose second number is the least, and so on.

    Your output format should imitate the sample output. Print a blank line after each test case.

    Sample Input

    4 1
    2 2 1 1
    2 2 1 1
    1 1 2 2
    1 1 2 2

    0 0

    Sample Output

    Case 1:
    1 2 1 2 3 4 3 42285322853

    Source

    样例输入

    4 1
    2 2 1 1
    2 2 1 1
    1 1 2 2
    1 1 2 2

    0 0

    样例输出

    Case 1:
    1 2 1 2 3 4 3 42285322853

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部