fengshui

2010-06-09 01:06:51
Judge Info
  • Memory Limit: 32768KB
  • Case Time Limit: 10000MS
  • Time Limit: 30000MS
  • Judger: Normal
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 modern 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, once element can kill another element, and one element can born anther element. Five elements compose as a circuit, as in Figure 1.

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:
    • TURN: The whole situation turn clockwise one step. Figure 3 shows the situation that situation in Figure 2 makes one TURN change.
    • 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.

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

    Now, there're two Fengshui situation, we want to know is it possible that first one can change to the second one? And if possible, how many steps it need 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 indeicate 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, if it is possible, or output -1.

    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
    用BFS,但可能会超时,所以用了双向BFS微笑

    ==参考代码==

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

    • 0
      点赞
    • 0
      收藏
      觉得还不错? 一键收藏
    • 1
      评论

    “相关推荐”对你有帮助么?

    • 非常没帮助
    • 没帮助
    • 一般
    • 有帮助
    • 非常有帮助
    提交
    评论 1
    添加红包

    请填写红包祝福语或标题

    红包个数最小为10个

    红包金额最低5元

    当前余额3.43前往充值 >
    需支付:10.00
    成就一亿技术人!
    领取后你会自动成为博主和红包主的粉丝 规则
    hope_wisdom
    发出的红包
    实付
    使用余额支付
    点击重新获取
    扫码支付
    钱包余额 0

    抵扣说明:

    1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
    2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

    余额充值