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

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 飛飛 閱讀(2722) 評論(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>
            亚洲美女视频在线观看| 国产欧美日韩视频| 正在播放亚洲一区| 亚洲精品一区二区在线| 久久精品免视看| 欧美在线观看www| 久久久精彩视频| 免费视频最近日韩| 亚洲国产精品专区久久| 欧美福利专区| 亚洲免费成人av电影| 亚洲国产综合在线看不卡| 日韩香蕉视频| 亚洲永久免费| 久久人人爽人人| 欧美11—12娇小xxxx| 欧美日韩精品高清| 国产伦精品免费视频| 韩日精品中文字幕| 亚洲大黄网站| 欧美亚洲一区二区三区| 久久综合国产精品台湾中文娱乐网| 亚洲影音一区| 欧美一区91| 免费在线欧美黄色| 91久久久久| 久久丁香综合五月国产三级网站| 欧美一区二视频在线免费观看| 久久精品国产久精国产一老狼| 巨乳诱惑日韩免费av| 国产精品久久影院| 国产亚洲欧美激情| 亚洲韩国精品一区| 久久久久久国产精品mv| 麻豆freexxxx性91精品| 99一区二区| 麻豆精品网站| 国产三级精品在线不卡| 最新国产乱人伦偷精品免费网站| 午夜精品三级视频福利| 欧美大片在线观看一区二区| 午夜影院日韩| 国产精品久久国产精麻豆99网站| 亚洲激情中文1区| 噜噜噜91成人网| 亚洲一区二区三区中文字幕| 欧美三级电影一区| 99精品99| 欧美激情偷拍| 六月婷婷一区| 在线观看欧美亚洲| 蜜臀av一级做a爰片久久| 亚洲欧美精品伊人久久| 欧美亚男人的天堂| 在线亚洲电影| 亚洲人www| 欧美激情亚洲| 亚洲精品一级| 亚洲韩国青草视频| 欧美精品首页| 一本久道综合久久精品| 亚洲国内精品| 欧美日韩免费区域视频在线观看| 亚洲精品综合久久中文字幕| 亚洲第一级黄色片| 欧美日韩爆操| 亚洲一区二区三区视频| 亚洲综合第一| 国产自产2019最新不卡| 久色成人在线| 欧美777四色影视在线| 亚洲美女性视频| 99视频精品免费观看| 国产精品嫩草影院av蜜臀| 午夜激情久久久| 香蕉久久夜色精品| 伊人蜜桃色噜噜激情综合| 亚洲国产精品一区二区www在线| 欧美日韩不卡| 欧美专区福利在线| 免播放器亚洲一区| 中文日韩电影网站| 亚洲一区二区三区精品动漫| 国产三级欧美三级日产三级99| 久久偷窥视频| 欧美国产先锋| 亚洲欧美高清| 欧美中文字幕视频| 夜夜爽夜夜爽精品视频| 亚洲欧美国产毛片在线| 国模精品一区二区三区| 亚洲福利视频专区| 久久综合狠狠综合久久激情| 日韩午夜激情| 久久五月天婷婷| 夜夜爽99久久国产综合精品女不卡 | 欧美18av| 亚洲欧美国产不卡| 久久久久欧美精品| 一区二区三区四区五区精品| 午夜精品久久久久久久99热浪潮 | 欧美午夜不卡| 久久只精品国产| 欧美日韩在线三区| 久久久一区二区三区| 欧美日韩成人在线播放| 久久亚洲影音av资源网| 欧美日韩一区三区四区| 另类春色校园亚洲| 国产精品久久久久久亚洲调教| 欧美xx视频| 国产亚洲精品高潮| 一区二区欧美日韩| 91久久久久久国产精品| 欧美一区二区三区男人的天堂| 亚洲视频欧美在线| 欧美电影免费观看| 蜜臀99久久精品久久久久久软件| 国产伦理一区| 亚洲看片一区| 亚洲精品免费电影| 噜噜噜躁狠狠躁狠狠精品视频| 欧美一区二区三区在| 国产精品福利av| 亚洲国产乱码最新视频| 在线观看国产一区二区| 久久av红桃一区二区小说| 午夜伦欧美伦电影理论片| 欧美欧美午夜aⅴ在线观看| 欧美大片免费久久精品三p| 好吊色欧美一区二区三区视频| 亚洲欧美日韩区 | 亚洲精品久久久久久久久久久| 亚洲电影观看| 鲁大师成人一区二区三区| 欧美成人综合网站| 亚洲国产精品专区久久| 麻豆成人av| 亚洲国产另类精品专区| 亚洲美女毛片| 欧美日韩一本到| 一区二区欧美在线| 欧美一级淫片播放口| 国产欧美欧美| 久久av一区二区| 老色鬼久久亚洲一区二区| 黄色国产精品| 麻豆av福利av久久av| 最新日韩精品| 亚洲一区欧美| 日韩一二三区视频| 性一交一乱一区二区洋洋av| 欧美 日韩 国产一区二区在线视频 | 99视频超级精品| 亚洲欧美另类国产| 国产精品久久久久久五月尺| 亚洲少妇诱惑| 久久精品国产精品亚洲精品| 韩日精品视频| 欧美高清在线精品一区| 在线一区二区三区做爰视频网站| 亚洲自拍偷拍麻豆| 国产亚洲欧美日韩美女| 蜜臀av在线播放一区二区三区| 亚洲精品国产精品国自产在线| 亚洲午夜电影在线观看| 国产裸体写真av一区二区| 久久女同互慰一区二区三区| 亚洲国产精品久久久久婷婷884| 亚洲午夜羞羞片| 国内精品亚洲| 欧美日韩国产区| 欧美一区二区视频在线| 亚洲国产精品悠悠久久琪琪| 欧美一区=区| 亚洲美女色禁图| 国产网站欧美日韩免费精品在线观看 | 久久综合久久综合九色| 亚洲一区二区3| 久久久免费av| 一卡二卡3卡四卡高清精品视频| 国产精品热久久久久夜色精品三区| 久久亚洲精品一区| 亚洲午夜女主播在线直播| 欧美风情在线观看| 欧美一级网站| 一本色道综合亚洲| 在线看欧美日韩| 国产欧美视频一区二区| 欧美精品一区二区久久婷婷| 欧美与黑人午夜性猛交久久久| 日韩午夜剧场| 91久久精品日日躁夜夜躁国产| 免费不卡在线视频| 欧美一区二区三区在线看| 在线一区二区三区做爰视频网站| 影音先锋在线一区| 国产一区二区主播在线| 国产精品视屏| 国产精品美女一区二区在线观看|