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

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 飛飛 閱讀(2732) 評論(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>
            伊人久久亚洲热| 国产真实久久| 一本色道久久88精品综合| 欧美sm视频| 美日韩精品免费| 亚洲精品一区二区网址 | 亚洲欧洲午夜| 久久网站免费| 亚洲看片一区| 9久草视频在线视频精品| 欧美午夜精品久久久久久超碰| 亚洲色图自拍| 亚洲欧美激情视频| 尹人成人综合网| 亚洲国产欧美另类丝袜| 欧美日韩另类综合| 性欧美办公室18xxxxhd| 欧美一级淫片播放口| 在线看国产一区| 日韩午夜黄色| 国产一区二区三区四区三区四| 免费日韩av| 欧美午夜在线一二页| 久久久午夜精品| 欧美好骚综合网| 香蕉久久国产| 欧美福利在线| 久久福利资源站| 蘑菇福利视频一区播放| 亚洲欧美激情一区二区| 久久久人成影片一区二区三区观看| 日韩天天综合| 午夜久久久久久| aa级大片欧美| 久久久成人精品| 亚洲一级片在线观看| 欧美在线精品免播放器视频| 99国产精品久久久久久久成人热| 午夜激情亚洲| 一本色道综合亚洲| 久久精品首页| 亚洲欧美日韩一区在线| 欧美波霸影院| 久久久久久久久岛国免费| 欧美久久久久免费| 国产日产高清欧美一区二区三区| 亚洲国产三级在线| 国产亚洲精品7777| 日韩一级成人av| 美女免费视频一区| 欧美在线免费观看视频| 欧美日韩国产va另类| 久久亚洲国产精品日日av夜夜| 欧美日韩亚洲在线| 欧美成人精品激情在线观看| 国内伊人久久久久久网站视频| 亚洲婷婷国产精品电影人久久| 一本久道久久综合狠狠爱| 久久全球大尺度高清视频| 国产精品素人视频| 一区二区免费看| 在线一区二区日韩| 欧美激情久久久久| 亚洲高清在线视频| 亚洲福利免费| 蜜桃精品久久久久久久免费影院| 久色婷婷小香蕉久久| 国产日韩精品在线观看| 亚洲欧美日韩视频一区| 欧美午夜精品理论片a级大开眼界| 欧美激情一二三区| 在线观看亚洲精品视频| 久久久久久免费| 久久综合999| 伊伊综合在线| 欧美成人午夜激情视频| 亚洲国产视频一区二区| 日韩一级大片| 欧美日韩在线免费| av72成人在线| 性色av一区二区三区红粉影视| 国产日韩欧美日韩| 久久精品噜噜噜成人av农村| 免费日韩成人| 99在线精品观看| 国产精品久久999| 亚洲欧美综合国产精品一区| 久久久天天操| 亚洲国产日韩一区二区| 欧美男人的天堂| 亚洲伊人一本大道中文字幕| 久久九九精品99国产精品| 一区久久精品| 欧美日韩人人澡狠狠躁视频| 午夜视频在线观看一区二区三区| 久久深夜福利| 亚洲精品日产精品乱码不卡| 国产精品户外野外| 欧美在线观看视频一区二区三区 | 亚洲高清视频在线观看| 欧美精选午夜久久久乱码6080| 999亚洲国产精| 久久精品国产亚洲5555| 亚洲免费高清| 国产一区二区精品久久99| 欧美激情精品久久久久久久变态| 亚洲在线不卡| 欧美激情一区二区在线 | 欧美影院一区| 亚洲国产一区二区精品专区| 国产精品高潮呻吟久久| 久久久免费av| 亚洲在线中文字幕| 欧美激情免费在线| 欧美视频日韩视频| 久久av一区| 99综合精品| 亚洲福利免费| 久久久青草婷婷精品综合日韩| 欧美成人免费大片| 亚洲欧美日韩国产成人| 亚洲国产第一| 久久亚洲一区二区| 亚洲欧美另类在线观看| 亚洲激情小视频| 国产日韩欧美一区在线 | 亚洲在线视频| 亚洲国产小视频在线观看| 久久av二区| 亚洲欧美日韩爽爽影院| 亚洲麻豆视频| 最近看过的日韩成人| 国产人妖伪娘一区91| 欧美日韩视频一区二区三区| 欧美激情中文字幕在线| 久久中文字幕一区| 欧美在线观看视频一区二区| 亚洲欧美一区二区三区在线 | 亚洲欧洲av一区二区三区久久| av不卡在线观看| 亚洲国产第一| 18成人免费观看视频| 影音先锋久久资源网| 国模私拍一区二区三区| 国产视频久久| 国产欧美日本一区视频| 国产欧美日韩视频在线观看| 国产精品久久毛片a| 国产精品久久波多野结衣| 欧美午夜久久久| 国产精品vvv| 国产精品一区免费观看| 国产精品久久一卡二卡| 国产精品久久久久久久久久免费| 欧美视频精品在线| 国产精品久久夜| 国产日韩欧美在线| 国产综合av| 亚洲国产福利在线| 日韩午夜激情av| 亚洲一区二区三区四区五区午夜 | 伊人久久大香线蕉综合热线| 在线看成人片| 一本色道**综合亚洲精品蜜桃冫 | 欧美激情欧美激情在线五月| 欧美激情精品久久久久久蜜臀| 亚洲欧洲日韩综合二区| 日韩一区二区高清| 亚洲一区日韩| 久久久精品999| 欧美激情中文字幕乱码免费| 国产精品免费网站在线观看| 国产在线观看一区| 亚洲国产成人在线| 亚洲午夜在线| 久久久国产一区二区| 欧美成人xxx| 中文国产一区| 卡一卡二国产精品| 欧美日韩精品一区二区三区| 国产美女精品人人做人人爽| 亚洲激情在线视频| 亚洲欧美在线aaa| 欧美第一黄网免费网站| 日韩天堂在线观看| 欧美中在线观看| 欧美日本国产| 狠狠色丁香婷婷综合影院| 一区二区三区欧美在线| 久久久久国内| 日韩一二三区视频| 久久视频国产精品免费视频在线| 欧美性大战久久久久久久| 精久久久久久久久久久| 亚洲永久免费观看| 欧美aaaaaaaa牛牛影院| 亚洲免费视频在线观看| 欧美黄色网络| 午夜精品久久久99热福利| 欧美粗暴jizz性欧美20|