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

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
謝謝大牛分享?。。?nbsp; 回復  更多評論
  
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            亚洲欧美综合另类中字| 久久精品国产91精品亚洲| 欧美3dxxxxhd| 麻豆精品国产91久久久久久| 国产一区二区久久久| 欧美在线一级视频| 久久精品成人| 亚洲国产精品欧美一二99| 亚洲二区在线观看| 欧美精品亚洲精品| 亚洲欧美日韩综合一区| 午夜精品一区二区三区电影天堂| 国产日韩欧美综合精品| 看片网站欧美日韩| 欧美精品日韩| 亚洲一区在线观看视频 | 99精品欧美一区二区三区综合在线| 欧美激情麻豆| 欧美小视频在线观看| 欧美综合77777色婷婷| 久久这里有精品视频| 一区二区电影免费观看| 亚洲免费视频在线观看| 亚洲国产经典视频| 99一区二区| 国产永久精品大片wwwapp| 亚洲大胆av| 国产精品入口尤物| 欧美成人亚洲成人日韩成人| 欧美日韩第一页| 久久久久久亚洲精品中文字幕| 久久亚洲欧洲| 午夜精品福利视频| 久久综合色综合88| 亚洲一区二区四区| 麻豆精品一区二区av白丝在线| 在线亚洲电影| 六月婷婷久久| 久久精品综合| 欧美性大战久久久久久久蜜臀| 久久天堂av综合合色| 欧美日韩专区| 欧美黄色视屏| 国产原创一区二区| 亚洲一二三区在线观看| 亚洲精品一区二区网址| 欧美在线黄色| 午夜日韩在线| 国产精品r级在线| 91久久香蕉国产日韩欧美9色| 国产午夜久久| 亚洲欧美国产视频| 亚洲欧美日韩在线| 欧美色精品在线视频| 亚洲第一中文字幕| 一区精品久久| 久久riav二区三区| 欧美资源在线观看| 国产精品亚发布| 在线视频欧美日韩| 一本色道久久综合狠狠躁篇怎么玩| 久久久av水蜜桃| 久久久夜精品| 狠狠色综合一区二区| 久久国产精品一区二区三区四区| 亚洲欧美日韩国产综合| 欧美三级视频在线播放| 99在线|亚洲一区二区| 中文一区二区在线观看| 欧美日韩国产精品一卡| 亚洲精品看片| 亚洲素人一区二区| 国产精品久久久久影院亚瑟| 一区二区三区不卡视频在线观看| 99re8这里有精品热视频免费 | 香蕉久久夜色精品国产使用方法| 亚洲欧美bt| 国产精品男人爽免费视频1| 亚洲视频精品| 久久久久国产精品厨房| 狠狠色丁香婷婷综合| 久久综合久久综合这里只有精品 | 欧美一区2区三区4区公司二百| 欧美午夜久久久| 亚洲欧美日韩精品久久久| 久久99伊人| 亚洲成人资源| 欧美人交a欧美精品| 一区二区欧美激情| 欧美一区二区三区播放老司机| 国产伦精品一区二区三区高清| 欧美在线观看www| 亚洲大片一区二区三区| 中文有码久久| 精品不卡一区| 欧美精品日韩三级| 亚洲综合社区| 欧美大色视频| 亚洲欧美日韩视频二区| 韩国免费一区| 欧美日韩国产在线一区| 亚洲欧美精品伊人久久| 免费一级欧美片在线播放| 99热在这里有精品免费| 国产麻豆9l精品三级站| 免费看亚洲片| 亚洲宅男天堂在线观看无病毒| 美国十次了思思久久精品导航| 日韩视频在线观看免费| 国产视频观看一区| 欧美日韩mp4| 久久精品国产久精国产爱| 亚洲精品国产精品国自产观看| 亚洲欧美日韩国产成人精品影院 | 欧美激情性爽国产精品17p| 亚洲专区免费| 亚洲精品五月天| 久久久亚洲国产美女国产盗摄| 夜夜爽99久久国产综合精品女不卡| 国产精品揄拍500视频| 欧美另类变人与禽xxxxx| 欧美一区二区三区久久精品茉莉花 | 中文在线一区| 亚洲黄色成人网| 国语自产精品视频在线看| 国产精品久久久久久久9999| 蜜臀久久99精品久久久久久9| 亚洲欧美日韩在线综合| av成人毛片| 最新69国产成人精品视频免费| 久久精品亚洲精品| 羞羞漫画18久久大片| 在线视频精品| 亚洲九九爱视频| 亚洲国产精品t66y| 在线精品国精品国产尤物884a| 国产精品入口麻豆原神| 欧美午夜精品久久久久久浪潮| 美女视频网站黄色亚洲| 久久久久久综合网天天| 久久精品九九| 久久xxxx精品视频| 性刺激综合网| 欧美一区精品| 久久国内精品视频| 久久精品成人一区二区三区| 先锋影音久久久| 午夜性色一区二区三区免费视频| 亚洲图片自拍偷拍| 亚洲一级黄色av| 亚洲一区免费看| 香蕉免费一区二区三区在线观看| 亚洲欧美高清| 久久精品国产免费| 久久免费视频观看| 美女任你摸久久| 欧美精品三区| 国产精品美女黄网| 国产欧美日韩一区二区三区| 国产精品自拍一区| 黄色资源网久久资源365| 在线电影欧美日韩一区二区私密| 伊人久久亚洲热| 亚洲人成在线观看网站高清| 亚洲精品在线电影| 中日韩在线视频| 欧美在线999| 蜜臀久久99精品久久久久久9| 欧美成人黄色小视频| 亚洲高清在线| 亚洲香蕉视频| 久久久成人精品| 欧美日韩成人| 国产午夜精品久久久| 在线日韩中文字幕| 一区二区av在线| 久久久综合香蕉尹人综合网| 欧美好骚综合网| 亚洲视频每日更新| 久久在线免费| 国产精品wwwwww| 伊人春色精品| 亚洲小视频在线| 美女国产一区| 亚洲婷婷在线| 免播放器亚洲一区| 国产精品青草久久| 亚洲国产欧美日韩精品| 亚洲愉拍自拍另类高清精品| 久久久水蜜桃av免费网站| 亚洲精品日韩精品| 久久久久欧美精品| 国产精品久久福利| 亚洲精品乱码| 久久久人成影片一区二区三区| 日韩一区二区久久| 免费观看久久久4p| 国产揄拍国内精品对白| 亚洲性感激情| 亚洲第一区色|