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

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>
            亚洲午夜激情网页| 久久婷婷国产综合国色天香| 亚洲小说春色综合另类电影| 国产亚洲成人一区| 国产精品视频一区二区高潮| 欧美午夜剧场| 国产精品色午夜在线观看| 欧美日韩中文在线观看| 欧美日韩国语| 国产日韩在线不卡| 精品不卡在线| 99天天综合性| 欧美在线一区二区| 欧美freesex交免费视频| 91久久精品国产91久久性色tv| 欧美激情成人在线视频| 99一区二区| 久久久久久一区二区| 欧美激情一区| 国产亚洲a∨片在线观看| 在线播放精品| 欧美一区二区视频在线| 亚洲国产经典视频| 久久精品99国产精品日本| 欧美日韩国产精品成人| 亚洲盗摄视频| 久久久久久穴| 欧美激情一区| 久久激情视频| 国产精品美女在线| 亚洲视频精品在线| 亚洲第一视频网站| 久久综合中文字幕| 国模吧视频一区| 午夜宅男欧美| 亚洲欧美色婷婷| 国产精品网站在线| 欧美在线视频观看| 欧美在线免费观看| 国产精品丝袜xxxxxxx| 午夜国产精品视频免费体验区| av成人老司机| 国产视频精品va久久久久久| 久久国产婷婷国产香蕉| 久久激情综合网| 最新国产乱人伦偷精品免费网站| 欧美大片专区| 欧美深夜福利| 久热精品视频在线观看| 欧美精品色综合| 久久精品二区| 欧美精品大片| 久久久久一区二区| 欧美暴力喷水在线| 性18欧美另类| 欧美18av| 久久精品麻豆| 国产精品高潮呻吟久久av无限| 久久久久国色av免费看影院| 欧美α欧美αv大片| 久久全国免费视频| 国产精品久久久久9999高清| 亚洲一区图片| 狠狠爱www人成狠狠爱综合网| 亚洲国产精品专区久久| 国产一区二区精品丝袜| 亚洲美女一区| 一区二区三欧美| 老司机aⅴ在线精品导航| 久久精品一区二区三区不卡| 国产精品mm| 亚洲精选大片| 亚洲线精品一区二区三区八戒| 久久久久在线| 欧美韩日视频| 亚洲黄网站黄| 欧美激情1区| 99精品欧美一区二区蜜桃免费| 亚洲国产日韩在线| 欧美成人午夜激情| 亚洲精品欧美| 亚洲伊人伊色伊影伊综合网| 欧美日韩爆操| 亚洲图片欧洲图片av| 性欧美暴力猛交69hd| 国产一区二区高清不卡| 久久久久久久久一区二区| 麻豆精品在线播放| 亚洲三级免费观看| 国产精品青草久久| 久久综合给合久久狠狠狠97色69| 免费欧美日韩国产三级电影| 亚洲美女av网站| 国产精品一区二区在线观看网站| 欧美中文字幕不卡| 亚洲青色在线| 久久亚洲图片| 亚洲影音一区| 亚洲精品视频一区二区三区| 国产精品婷婷| 亚洲欧洲一区二区天堂久久| 男男成人高潮片免费网站| 妖精成人www高清在线观看| 久久精品一区二区三区不卡| 亚洲视频免费| 亚洲美女福利视频网站| 黄色亚洲免费| 国产伦精品一区二区三区四区免费| 欧美大片免费久久精品三p| 欧美怡红院视频| 亚洲中字在线| 亚洲午夜久久久| 制服丝袜亚洲播放| 日韩午夜精品| 一本久道久久综合婷婷鲸鱼| 欧美高清hd18日本| 欧美激情欧美狂野欧美精品| 免费欧美日韩国产三级电影| 久久婷婷国产综合国色天香| 欧美伊人影院| 免费短视频成人日韩| 蜜臀久久久99精品久久久久久| 久久精品亚洲一区二区三区浴池| 欧美一区二区黄色| 欧美.www| 一本一本大道香蕉久在线精品| 亚洲一二三区在线| 久久久久久久久岛国免费| 欧美高清视频在线播放| 欧美日韩在线看| 国产一区在线播放| 亚洲精一区二区三区| 欧美怡红院视频| 亚洲高清在线精品| 亚洲男人的天堂在线| 免费一级欧美片在线播放| 国产精品免费观看视频| 在线日韩中文字幕| 欧美在线视频观看免费网站| 美国三级日本三级久久99| 一区二区三区回区在观看免费视频| 欧美日韩成人一区二区| 欧美一区二区三区啪啪 | 欧美大成色www永久网站婷| 欧美小视频在线| 一本色道久久综合亚洲精品按摩| 久久亚洲精品一区| 久久精品国产99精品国产亚洲性色| 欧美精品尤物在线| 亚洲国产日韩欧美在线99| 欧美一区精品| 亚洲一级特黄| 国产精品成人午夜| 亚洲伊人网站| 亚洲素人一区二区| 国产精品爽爽ⅴa在线观看| 一区二区三区四区国产| 99在线精品观看| 国产精品捆绑调教| 欧美综合国产精品久久丁香| 亚洲永久免费| 国内免费精品永久在线视频| 久久久精品国产免大香伊| 久久久久久穴| 99精品视频免费| 亚洲午夜激情网站| 狠狠色丁香婷婷综合| 欧美成人一区二区三区在线观看 | 久久精品一区二区国产| 久久在线精品| 一区二区91| 久久精品99无色码中文字幕| 亚洲国产国产亚洲一二三| 99伊人成综合| 1000部精品久久久久久久久| 99精品国产一区二区青青牛奶| 国产精品video| 亚洲高清123| 国产亚洲精品aa| 亚洲精品孕妇| 1000部国产精品成人观看| 亚洲天堂av电影| 亚洲二区免费| 国产精品福利网站| 欧美激情按摩在线| 黄色成人在线| 欧美中文日韩| 久久精品人人| 国产欧美一区二区精品秋霞影院 | 夜久久久久久| 日韩一二三在线视频播| 久久综合婷婷| 欧美激情一区二区三区成人 | 久久av一区| 久久九九99视频| 国产区二精品视| 欧美中文字幕不卡| 蜜桃久久av一区| 91久久久久久久久| 欧美日韩影院|