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

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>
            久久亚洲国产精品一区二区| 亚洲第一色中文字幕| 欧美11—12娇小xxxx| 欧美日韩精品中文字幕| 久久综合电影一区| 国产精品另类一区| 亚洲黄色免费| 韩日欧美一区二区三区| 亚洲一区美女视频在线观看免费| 亚洲国产欧洲综合997久久| 午夜亚洲福利| 亚洲综合首页| 久久日韩精品| 久久中文久久字幕| 久久久久久久97| 国产亚洲精久久久久久| 亚洲天堂av电影| 亚洲一区在线观看视频| 欧美日韩成人网| 亚洲精品久久久久久一区二区| 亚洲第一福利社区| 久久久久久高潮国产精品视| 久久精品欧洲| 国产日韩一区欧美| 欧美一二三区在线观看| 久久精品亚洲一区| 国内不卡一区二区三区| 欧美在线不卡| 麻豆精品国产91久久久久久| 影音先锋日韩精品| 久久噜噜亚洲综合| 欧美电影电视剧在线观看| 欧美大片一区二区| 亚洲精品视频在线观看网站| 一本色道久久综合| 国产精品都在这里| 欧美一区二区三区啪啪| 老妇喷水一区二区三区| 亚洲国产欧美另类丝袜| 欧美精品麻豆| 免费日韩成人| 99国产精品国产精品毛片| 欧美精品在线观看91| 这里只有精品丝袜| 久久久999精品| 亚洲第一级黄色片| 欧美日韩国产高清| 中文亚洲免费| 久久一区二区三区av| 亚洲黄色三级| 欧美午夜免费影院| 欧美在线影院在线视频| 亚洲高清一区二| 亚洲一区不卡| 国产一区二区视频在线观看| 久久久www成人免费无遮挡大片| 欧美超级免费视 在线| 中文久久乱码一区二区| 国产日韩精品在线| 欧美aⅴ一区二区三区视频| 99精品欧美一区二区三区| 欧美一级片在线播放| 亚洲国产乱码最新视频| 国产精品久久久久久久久免费樱桃| 欧美一级视频精品观看| 亚洲缚视频在线观看| 午夜天堂精品久久久久| 亚洲成色www8888| 欧美婷婷在线| 老司机一区二区三区| 亚洲视频在线观看视频| 欧美国产精品久久| 亚洲你懂的在线视频| 亚洲国产欧美一区| 国产午夜精品久久| 欧美精品999| 久久精品在线视频| 这里只有视频精品| 亚洲欧洲视频| 久久久91精品| 亚洲欧美在线观看| 亚洲伦理在线| 一区精品在线播放| 国产精品美女久久| 欧美日本亚洲| 免费不卡在线观看av| 午夜视频一区二区| 一区二区高清视频在线观看| 亚洲欧洲日产国产网站| 国产一在线精品一区在线观看| 欧美精品激情在线观看| 久久久久欧美| 欧美一区二区三区男人的天堂 | 亚洲综合色婷婷| 欧美激情一级片一区二区| 久久国产精品免费一区| 亚洲欧美视频| 这里只有精品视频在线| 亚洲精品日本| 亚洲激情校园春色| 在线成人国产| 在线国产欧美| 国产在线观看精品一区二区三区| 国产精品久久久免费| 欧美三级日韩三级国产三级| 欧美激情精品久久久久久大尺度 | 亚洲午夜电影网| 亚洲看片一区| 日韩天堂在线观看| 日韩视频一区| 一本色道久久综合亚洲精品小说 | 永久555www成人免费| 国产亚洲欧洲一区高清在线观看 | 国产精品国产三级欧美二区| 国产精品va在线| 国产精品hd| 国产精品一区免费观看| 国产美女精品视频| 国产亚洲一级高清| 亚洲第一视频| 99视频有精品| 亚洲综合三区| 久久精品国产清自在天天线| 久久久久久久久久码影片| 久久亚洲精选| 亚洲国内高清视频| av成人手机在线| 亚洲欧美日韩在线综合| 久久精品国产亚洲高清剧情介绍| 久久精品视频网| 欧美久久电影| 国产精品一区二区久久久| 黄色资源网久久资源365| 亚洲国产日韩欧美一区二区三区| 亚洲美女av黄| 欧美伊人影院| 欧美成人免费在线视频| 亚洲美女免费视频| 西瓜成人精品人成网站| 免费成人性网站| 国产精品福利久久久| 好吊成人免视频| 亚洲色在线视频| 久久精品色图| 91久久久久久久久久久久久| 亚洲性夜色噜噜噜7777| 老司机免费视频一区二区| 欧美性事在线| 亚洲电影免费观看高清完整版在线观看 | 亚洲欧美日韩人成在线播放| 久久久久久久久久看片| 亚洲欧洲一区二区天堂久久| 亚洲综合视频网| 欧美成人精品一区| 国产精品资源| 一本高清dvd不卡在线观看| 久久九九国产精品| 日韩亚洲在线观看| 久久久久免费视频| 国产精品一区免费视频| 夜夜狂射影院欧美极品| 久久久视频精品| 亚洲视频一起| 欧美激情2020午夜免费观看| 国产在线欧美| 午夜在线视频一区二区区别| 亚洲国产裸拍裸体视频在线观看乱了中文 | 在线欧美小视频| 欧美在线国产精品| 亚洲精品欧美日韩专区| 久久天天狠狠| 国产一区亚洲| 久久精品国产99国产精品澳门| 99精品视频免费在线观看| 美日韩精品视频免费看| 国模精品一区二区三区| 欧美一级久久久| 一区二区三区四区五区精品视频 | 亚洲东热激情| 久久精品久久99精品久久| 亚洲深夜av| 欧美性视频网站| 亚洲天堂成人| 亚洲精品影院| 欧美精品一区二区三| 亚洲欧洲一区二区在线观看| 男女视频一区二区| 麻豆精品视频| 91久久精品国产91性色tv| 久久综合九色综合欧美狠狠| 欧美一区国产二区| 国产真实精品久久二三区| 欧美一区二区三区视频在线观看| 亚洲一级一区| 国产欧美一区二区三区久久| 午夜精品一区二区三区在线| 亚洲一区二区三区激情| 国产精品久久久久毛片软件| 亚洲一区免费看| 亚洲综合丁香|