21637_Fengshui

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

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

Pro.ID

21637

Title

Fengshui

Title链接

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

AC

0

Submit

1

Ratio

0.00%

时间&空间限制

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

    Fengshui is an ancient subject in Chinese tradition. Someone considers it as science and someone criticizes it as blind faith. Who knows! However, in modem days, everyone should respect culture from our ancestor!

    Fengshui focus on geography, environment and staffs' position, all the theory come from a very old book named "YI". YI means change. Everything is always changing in the world. Fengshui wishes to guide changing, make life change to a better situation. Now, let's look at Fengshui's changing.

    At first we must know about the traditional five elements system which composed by GOLD, WOOD, GROUND, WATER and FIRE. Everything in the world can be represented by one and only one element. For example, river is represented by WATER, HILL is represented by GROUND. Here, we only consider the elements. In this system, one element can kill another element, and one element can born another element. Five elements compose as a circuit, as in Figure 1.

    Figure 1  Kill and born

    Every place has eight direction -- east, west, north, south, northeast, northwest, southeast and southwest. Every direction has a represented element. Now, our problem is about the elements at these eight directions which form a Fengshui situation. Figure 2 is an example of one Fengshui situation.

    But Fengshui situation can change! There're two change ways:

    (1) TURN: The whole situation turn clockwise one step. Figure 3 shows the situation that situation in Figure 2 makes one TURN change.

    (2) REBORN: Based on kill and born relation, one direction's element can be killed by another direction's (at any other place) element in the situation, and then the killed element will born out as the new element at its direction. Of course, kill and born are all according as the relation of the system as in Figure 1. In situation of Figure 3, WATER in east can kill FIRE in southeast, then southeast place change to be GROUND, as in Figure 4.

    Figure 2                                    Figure 3                                     Figure 4

    Each change, no matter TURN or REBORN, costs one step.

    Now, there're two Fengshui situations, we want to know is it possible that first one can change to the second one? And if possible, how many steps it needs at least?

    输入

    There're several cases, the first line of input is the number of cases. Every case includes 6 lines, the first 3 lines indicate the first Fengshui situation, the last 3 lines incicate the second Fengshui situation.

    The format of one situation is as follow, there may be arbitrary blanks between adjacent directions.

    northwest  north  northeast
      west                      east
    southwest  south  southeast

    输出

    Description

    Fengshui is an ancient subject in Chinese tradition. Someone considers it as science and someone criticizes it as blind faith. Who knows! However, in modem days, everyone should respect culture from our ancestor!

    Fengshui focus on geography, environment and staffs' position, all the theory come from a very old book named "YI". YI means change. Everything is always changing in the world. Fengshui wishes to guide changing, make life change to a better situation. Now, let's look at Fengshui's changing.

    At first we must know about the traditional five elements system which composed by GOLD, WOOD, GROUND, WATER and FIRE. Everything in the world can be represented by one and only one element. For example, river is represented by WATER, HILL is represented by GROUND. Here, we only consider the elements. In this system, one element can kill another element, and one element can born another element. Five elements compose as a circuit, as in Figure 1.

    Figure 1  Kill and born

    Every place has eight direction -- east, west, north, south, northeast, northwest, southeast and southwest. Every direction has a represented element. Now, our problem is about the elements at these eight directions which form a Fengshui situation. Figure 2 is an example of one Fengshui situation.

    But Fengshui situation can change! There're two change ways:

    (1) TURN: The whole situation turn clockwise one step. Figure 3 shows the situation that situation in Figure 2 makes one TURN change.

    (2) REBORN: Based on kill and born relation, one direction's element can be killed by another direction's (at any other place) element in the situation, and then the killed element will born out as the new element at its direction. Of course, kill and born are all according as the relation of the system as in Figure 1. In situation of Figure 3, WATER in east can kill FIRE in southeast, then southeast place change to be GROUND, as in Figure 4.

    Figure 2                                    Figure 3                                     Figure 4

    Each change, no matter TURN or REBORN, costs one step.

    Now, there're two Fengshui situations, we want to know is it possible that first one can change to the second one? And if possible, how many steps it needs at least?

    Input

    There're several cases, the first line of input is the number of cases. Every case includes 6 lines, the first 3 lines indicate the first Fengshui situation, the last 3 lines incicate the second Fengshui situation.

    The format of one situation is as follow, there may be arbitrary blanks between adjacent directions.

    northwest  north  northeast
      west                      east
    southwest  south  southeast

    Output

    For every case, output the number of the least changing steps on a single line. Output -1 on a single line in case of no solution.

    Sample Input

    2
    GOLD  WOOD  WATER
    WATER        FIRE
    WOOD  GOLD  GROUND
    WATER GOLD   WOOD
    WOOD         WATER
    GOLD  GROUND GROUND
    WATER GROUND  WOOD
    GOLD          FIRE
    GOLD  FIRE    GROUND
    GOLD  FIRE   FIRE
    GOLD         FIRE
    WATER GROUND WOOD

    Sample Output

    2
    14

    Source

    样例输入

    2
    GOLD  WOOD  WATER
    WATER        FIRE
    WOOD  GOLD  GROUND
    WATER GOLD   WOOD
    WOOD         WATER
    GOLD  GROUND GROUND
    WATER GROUND  WOOD
    GOLD          FIRE
    GOLD  FIRE    GROUND
    GOLD  FIRE   FIRE
    GOLD         FIRE
    WATER GROUND WOOD

    样例输出

    2
    14

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部