青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

alpc60 ACM/ICPC程序設計
成長的路……源
posts - 20,comments - 42,trackbacks - 0

The Rotation Game

Time Limit: 15000MS

 

Memory Limit: 150000K

Total Submissions: 944

 

Accepted: 218

Description

The rotation game uses a # shaped board, which can hold 24 pieces of square blocks (see Fig.1). The blocks are marked with symbols 1, 2 and 3, with exactly 8 pieces of each kind.


Initially, the blocks are placed on the board randomly. Your task is to move the blocks so that the eight blocks placed in the center square have the same symbol marked. There is only one type of valid move, which is to rotate one of the four lines, each consisting of seven blocks. That is, six blocks in the line are moved towards the head by one block and the head block is moved to the end of the line. The eight possible moves are marked with capital letters A to H. Figure 1 illustrates two consecutive moves, move A and move C from some initial configuration.

Input

The input consists of no more than 30 test cases. Each test case has only one line that contains 24 numbers, which are the symbols of the blocks in the initial configuration. The rows of blocks are listed from top to bottom. For each row the blocks are listed from left to right. The numbers are separated by spaces. For example, the first test case in the sample input corresponds to the initial configuration in Fig.1. There are no blank lines between cases. There is a line containing a single `0' after the last test case that ends the input.

Output

For each test case, you must output two lines. The first line contains all the moves needed to reach the final configuration. Each move is a letter, ranging from `A' to `H', and there should not be any spaces between the letters in the line. If no moves are needed, output `No moves needed' instead. In the second line, you must output the symbol of the blocks in the center square after these moves. If there are several possible solutions, you must output the one that uses the least number of moves. If there is still more than one possible solution, you must output the solution that is smallest in dictionary order for the letters of the moves. There is no need to output blank lines between cases.

Sample Input

1 1 1 1 3 2 3 2 3 1 3 2 2 3 1 2 2 2 3 1 2 1 3 3
1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3
0

Sample Output

AC
2
DDHH
2

Source

Shanghai 2004

 

 

圖中的#字格的4條豎線,可以按8個方向倒轉里面的數字方塊,當中間的8個數字方塊是同一個數字時,游戲結束。這道題就要求搜索一個最短路徑,倒轉8個方向使得中間8個數字相等。這道題目看起來很像一道單純的BFS,看了POJ里面說BFS會爆內存,我沒試,估計寫得好的也爆不了。但是估計寫BFS還要涉及到狀態的判重,程序寫起來也不方便。我用了迭代加深的搜索方法。第一次接觸這個算法,我說一下我的理解:

       原來我很不理解迭代加深,搜索的深度一層一層地加,在后面的某一深度限制下搜索,必定會搜到前面深度所能搜到的結果,這會造成重復搜索。基于這點,我一直都認為迭代加深搜索的方法很冗余,當然也是自己從來都沒有動手試過。像這道題就給我的收獲不少,有的時候選擇一定的策略進行搜索,我們是很難確定解所在狀態空間的深度的,有時可能解的深度不大,但整個狀態空間的深度很大,盲目的dfs搜索在狀態空間里就有可能會越陷越深,遲遲出不了解,同時整個狀態空間的寬度也很大,用BFS可能就會爆空間。迭代加深搜索恰恰是取了一個折中。利用了dfs的優勢,限制了搜索的深度,避免了出現無解的境地。由于深度是逐個增加的,當搜到一個解后就退出,所以避免了BFS中判重的一步操作,當然在迭代深搜的過程中,還可以加入剪枝,可以優化程序。但是我的程序在POJ上還不快,還要找找原因,也許還有優化。下面是一些關鍵代碼:


for(limit=0; ;limit++)
        
{
            
if(dfs(start,0))
            
{
                
if(limit == 0)
                
{
                    printf(
"No moves needed\n");
                }

                
else
                
{
                    
for(i=0; i<limit; i++)
                    
{
                        printf(
"%c",'A'+pre[i]);
                    }

                    printf(
"\n");
                }

                printf(
"%d\n",rlt);
                
break;
            }

        }

///迭代過程
int dfs(struct S now, int depth)
{
    
int c1,c2,c3;
    struct S st;
    test(now,c1,c2,c3);
    
if(c1 == 8)
    
{
        rlt
=1;
        
return 1;
    }

    
else if(c2 == 8)
    
{
        rlt
=2;
        
return 1;
    }

    
else if(c3 == 8)
    
{
        rlt
=3;
        
return 1;
    }

    
if(depth == limit)
        
return 0;
    
if(8-c1 > limit-depth && 8-c2 > limit-depth && 8-c3 > limit-depth)
        
return 0;
    st
=NewStateA(now);
    pre[depth]
=0;
    
if(dfs(st,depth+1))
        
return 1;
    st
=NewStateB(now);
    pre[depth]
=1;
    
if(dfs(st,depth+1))
        
return 1;
    st
=NewStateC(now);
    pre[depth]
=2;
    
if(dfs(st,depth+1))
        
return 1;
    st
=NewStateD(now);
    pre[depth]
=3;
    
if(dfs(st,depth+1))
        
return 1;
    st
=NewStateE(now);
    pre[depth]
=4;
    
if(dfs(st,depth+1))
        
return 1;
    st
=NewStateF(now);
    pre[depth]
=5;
    
if(dfs(st,depth+1))
        
return 1;
    st
=NewStateG(now);
    pre[depth]
=6;
    
if(dfs(st,depth+1))
        
return 1;
    st
=NewStateH(now);
    pre[depth]
=7;
    
if(dfs(st,depth+1))
        
return 1;
    
return 0;
}

///深搜
posted on 2008-04-20 15:44 飛飛 閱讀(2734) 評論(1)  編輯 收藏 引用 所屬分類: ACM/ICPC

FeedBack:
# re: 迭代加深搜索
2008-07-04 20:08 | wzc1989
謝謝大牛分享!!!  回復  更多評論
  
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            国产无一区二区| 亚洲精品欧美极品| 午夜久久一区| 亚洲一区二区免费视频| 国产精品久久久久久超碰| 亚洲性xxxx| 午夜电影亚洲| 一区二区视频免费在线观看 | 激情成人av| 免费亚洲网站| 欧美精品日韩综合在线| 亚洲综合色在线| 欧美一区二区成人6969| 亚洲国产国产亚洲一二三| 91久久久久久国产精品| 欧美午夜不卡视频| 久久国产福利国产秒拍| 久久综合99re88久久爱| 一本色道久久加勒比88综合| 亚洲欧美一区二区三区极速播放| 国内精品久久久久久影视8| 欧美成人精品在线| 欧美视频中文在线看| 欧美在线视频一区二区| 美女国产一区| 香蕉国产精品偷在线观看不卡| 欧美资源在线观看| 亚洲伦理在线免费看| 亚洲视频免费看| 亚洲国产三级| 亚洲免费在线| 一区二区三区国产精华| 欧美伊人影院| 亚洲综合国产精品| 老司机一区二区三区| 宅男在线国产精品| 另类激情亚洲| 久久99伊人| 欧美精品一区二区三区蜜臀| 久久久亚洲人| 国产精品美女主播在线观看纯欲| 欧美高清免费| 国产在线视频欧美一区二区三区| 亚洲另类春色国产| 亚洲国产欧美一区二区三区久久 | 久久夜精品va视频免费观看| 欧美日韩成人在线视频| 噜噜噜久久亚洲精品国产品小说| 欧美日韩在线视频首页| 亚洲第一精品夜夜躁人人躁| 国产亚洲精品激情久久| 亚洲视频免费在线观看| 亚洲美女黄色片| 久久夜色精品| 久久精品国产99精品国产亚洲性色 | 男女激情久久| 国产一区二区日韩精品| 亚洲午夜伦理| 亚洲视频在线播放| 欧美日韩国产精品一卡| 亚洲国产影院| 亚洲激情在线视频| 久久久久久久综合狠狠综合| 久久人人爽国产| 国产在线播放一区二区三区| 亚洲一区日韩在线| 午夜视频在线观看一区二区三区 | 亚洲欧美大片| 西西人体一区二区| 国产精品每日更新| 亚洲一区二区三区777| 亚洲色图在线视频| 欧美日韩一区二区精品| 亚洲美女淫视频| 亚洲免费成人| 欧美色图一区二区三区| 这里只有精品在线播放| 欧美一区二区在线免费观看| 国产精品日韩欧美大师| 亚洲一级二级| 久久精品人人爽| 激情久久久久久久久久久久久久久久| 久久精品综合一区| 欧美国内亚洲| 亚洲无线一线二线三线区别av| 欧美午夜欧美| 午夜精品国产更新| 美女视频黄a大片欧美| 亚洲日本欧美在线| 欧美日韩亚洲一区在线观看| 亚洲影视九九影院在线观看| 久久人人爽人人爽| 亚洲激情偷拍| 国产精品大片| 久久久久国产精品厨房| 亚洲电影免费观看高清完整版在线 | 久久噜噜噜精品国产亚洲综合| 免费在线观看成人av| 亚洲伦理在线观看| 国产精品夜色7777狼人 | 亚洲毛片av在线| 欧美在线播放| 亚洲免费成人av| 国产日韩精品久久久| 欧美11—12娇小xxxx| 亚洲视频中文字幕| 蜜臀99久久精品久久久久久软件 | 国产女精品视频网站免费| 久久久99爱| 中文av一区二区| 欧美成人一区二区三区| 亚洲一区二区三区在线播放| 国产又爽又黄的激情精品视频| 欧美激情一区三区| 久久精品国产2020观看福利| 91久久精品www人人做人人爽| 久久精品综合| 亚洲男同1069视频| 亚洲欧洲一区二区三区久久| 国产主播精品在线| 欧美日韩专区| 欧美精品网站| 久久一综合视频| 午夜精品免费视频| 亚洲美女免费精品视频在线观看| 另类激情亚洲| 久久精品1区| 亚洲欧美日韩国产精品| 亚洲精品一二三| 在线观看一区二区精品视频| 国产日韩在线一区| 国产精品中文字幕欧美| 欧美三区美女| 欧美日韩123| 欧美精品在线视频| 美日韩丰满少妇在线观看| 久久高清福利视频| 小黄鸭精品aⅴ导航网站入口| 一区二区激情| 99亚洲视频| 妖精视频成人观看www| 最近中文字幕mv在线一区二区三区四区 | 亚洲另类在线视频| 亚洲精品你懂的| 亚洲久久视频| 99精品国产在热久久下载| 亚洲区一区二区三区| 亚洲精品社区| 亚洲老司机av| 一本一道久久综合狠狠老精东影业| 亚洲日本精品国产第一区| 亚洲欧洲日本mm| 日韩手机在线导航| 9久草视频在线视频精品| 一本色道久久综合狠狠躁篇的优点| 亚洲六月丁香色婷婷综合久久| 日韩视频一区二区三区在线播放| 亚洲精品一区在线观看香蕉| 亚洲精品在线电影| 亚洲一区二区欧美| 欧美亚洲一区| 久久久人成影片一区二区三区| 久久中文字幕一区二区三区| 美女啪啪无遮挡免费久久网站| 欧美大片一区| 亚洲精品一区二区三区福利| 中日韩午夜理伦电影免费| 性18欧美另类| 免费黄网站欧美| 欧美日韩国产小视频| 国产精品日韩| 樱桃成人精品视频在线播放| 亚洲伦理在线| 久久国产欧美| 亚洲国产精品999| 亚洲一二三区精品| 久久在线视频| 欧美午夜精品久久久久久超碰| 国产日韩欧美一区二区三区四区| 一区二区三区无毛| 亚洲少妇在线| 玖玖国产精品视频| 亚洲美女av黄| 久久久久久久性| 国产精品九色蝌蚪自拍| 黄色日韩网站| 亚洲一区久久久| 欧美国产视频一区二区| 亚洲在线观看| 欧美日韩不卡合集视频| 一区二区三区我不卡| 亚洲一区黄色| 亚洲国产精品传媒在线观看 | 91久久在线| 欧美自拍丝袜亚洲| 欧美视频中文在线看| 亚洲国产一区二区a毛片| 欧美在线播放视频| 一本色道久久| 欧美日本一区二区三区|