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

POJ 1178 Camelot Floyd算法+枚舉

Description

Centuries ago, King Arthur and the Knights of the Round Table used to meet every year on New Year's Day to celebrate their fellowship. In remembrance of these events, we consider a board game for one player, on which one king and several knight pieces are placed at random on distinct squares.
The Board is an 8x8 array of squares. The King can move to any adjacent square, as shown in Figure 2, as long as it does not fall off the board. A Knight can jump as shown in Figure 3, as long as it does not fall off the board.

During the play, the player can place more than one piece in the same square. The board squares are assumed big enough so that a piece is never an obstacle for other piece to move freely.
The player抯 goal is to move the pieces so as to gather them all in the same square, in the smallest possible number of moves. To achieve this, he must move the pieces as prescribed above. Additionally, whenever the king and one or more knights are placed in the same square, the player may choose to move the king and one of the knights together henceforth, as a single knight, up to the final gathering point. Moving the knight together with the king counts as a single move.

Write a program to compute the minimum number of moves the player must perform to produce the gathering.

Input

Your program is to read from standard input. The input contains the initial board configuration, encoded as a character string. The string contains a sequence of up to 64 distinct board positions, being the first one the position of the king and the remaining ones those of the knights. Each position is a letter-digit pair. The letter indicates the horizontal board coordinate, the digit indicates the vertical board coordinate.

0 <= number of knights <= 63

Output

Your program is to write to standard output. The output must contain a single line with an integer indicating the minimum number of moves the player must perform to produce the gathering.

Sample Input

D4A3A8H1H8

Sample Output

10

Source


    棋盤上有1個國王和若干個騎士,要把國王和每個騎士移動到同一個格子內,問需要移動的最小步數是多少。如果國王和騎士走到同一個格子里,可以由騎士帶著國王一起移動。
    枚舉棋盤上的64個點作為終點,對于每一個假定的終點,再枚舉這64個點作為國王和某個騎士相遇的點,最后求出需要移動的最小步數。其中根據騎士和國王移動的特點可以預處理出從1個點到另外1個點所需的最小移動次數,也可用搜索。
#include <iostream>
using namespace std;

const int inf = 100000;
char str[150];
int k[64],king[64][64],knight[64][64];
int move1[8][2]={-1,-1,-1,0,-1,1,0,1,1,1,1,0,1,-1,0,-1};
int move2[8][2]={-1,-2,-2,-1,-2,1,-1,2,1,2,2,1,2,-1,1,-2};

void init(){
    
int i,j,x,y,tx,ty;
    
for(i=0;i<64;i++)
        
for(j=0;j<64;j++)
            
if(i==j) king[i][j]=knight[i][j]=0;
            
else king[i][j]=knight[i][j]=inf;
    
for(i=0;i<64;i++){
        x
=i/8,y=i%8;
        
for(j=0;j<8;j++){
            tx
=x+move1[j][0],ty=y+move1[j][1];
            
if(tx>=0 && ty>=0 && tx<8 && ty<8)
                king[i][
8*tx+ty]=1;
        }

    }

    
for(i=0;i<64;i++){
        x
=i/8,y=i%8;
        
for(j=0;j<8;j++){
            tx
=x+move2[j][0],ty=y+move2[j][1];
            
if(tx>=0 && ty>=0 && tx<8 && ty<8)
                knight[i][
8*tx+ty]=1;
        }

    }

}

void floyd1(){
    
int i,j,k;
    
for(k=0;k<64;k++)
        
for(i=0;i<64;i++)
            
for(j=0;j<64;j++)
                
if(king[i][k]+king[k][j]<king[i][j])
                    king[i][j]
=king[i][k]+king[k][j];
}

void floyd2(){
    
int i,j,k;
    
for(k=0;k<64;k++)
        
for(i=0;i<64;i++)
            
for(j=0;j<64;j++)
                
if(knight[i][k]+knight[k][j]<knight[i][j])
                    knight[i][j]
=knight[i][k]+knight[k][j];
}

int main(){
    
int i,j,l,cnt,pos,sum,ans,len,t1,t2;
    init();
    floyd1();
    floyd2();
    
while(scanf("%s",str)!=EOF){
        len
=strlen(str);
        pos
=(str[0]-'A')+(str[1]-'1')*8;
        cnt
=(len-2)/2;
        
if(cnt==0){
            printf(
"0\n");
            
continue;
        }

        
for(i=0,j=2;i<cnt;i++,j+=2)
            k[i]
=(str[j]-'A')+(str[j+1]-'1')*8;
        
for(ans=inf,i=0;i<64;i++){
            
for(sum=l=0;l<cnt;l++)
                sum
+=knight[k[l]][i];
            
for(j=0;j<64;j++){
                t1
=king[pos][j];
                
for(t2=inf,l=0;l<cnt;l++)
                    t2
=min(t2,knight[k[l]][j]+knight[j][i]-knight[k[l]][i]);
                ans
=min(ans,sum+t1+t2);
            }

        }

        printf(
"%d\n",ans);
    }

    
return 0;
}

posted on 2009-07-02 23:57 極限定律 閱讀(2355) 評論(0)  編輯 收藏 引用 所屬分類: ACM/ICPC

<2009年7月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

導航

統計

常用鏈接

留言簿(10)

隨筆分類

隨筆檔案

友情鏈接

搜索

最新評論

閱讀排行榜

評論排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            久久理论片午夜琪琪电影网| 亚洲四色影视在线观看| 久久久久免费视频| 欧美一二三区精品| 1024成人网色www| 亚洲第一色在线| 久久亚洲影音av资源网| 亚洲精品视频在线观看免费| 亚洲啪啪91| 国产精品无码专区在线观看| 久久精品人人爽| 欧美v国产在线一区二区三区| 日韩午夜av| 亚洲欧美伊人| 最新日韩av| 亚洲欧美日韩在线综合| 亚洲国产aⅴ天堂久久| 一本色道久久综合亚洲精品小说 | 欧美四级剧情无删版影片| 亚洲影院在线观看| 久久久久se| 亚洲午夜激情免费视频| 欧美一区二区在线免费播放| 一本色道久久综合狠狠躁的推荐| 亚洲精品乱码久久久久久蜜桃91| 欧美三级特黄| 久久综合国产精品| 国产精品高清在线观看| 免费成人高清| 国产欧美一区二区三区另类精品 | 99热在这里有精品免费| 精品白丝av| 亚洲一区二区三区久久| 亚洲国产日韩一区二区| 午夜精品剧场| 亚洲一区二区伦理| 欧美电影免费观看大全| 久久天堂av综合合色| 国产精品国产三级国产专播品爱网 | 欧美日韩国产在线一区| 蜜臀久久久99精品久久久久久 | 欧美成人免费一级人片100| 久久国产精品第一页| 欧美午夜剧场| 亚洲毛片av在线| 亚洲精品免费网站| 久久综合色一综合色88| 久久综合五月天婷婷伊人| 国产精品一区在线观看| 一本色道**综合亚洲精品蜜桃冫| 亚洲精品久久久一区二区三区| 久久九九热re6这里有精品| 欧美一区二区在线看| 国产精品久久夜| 一本色道久久88综合日韩精品| 亚洲久久在线| 欧美精品成人一区二区在线观看 | 中日韩在线视频| 欧美经典一区二区| 亚洲黄色在线观看| 亚洲国产成人不卡| 久久免费视频在线观看| 久久综合五月天婷婷伊人| 伊人狠狠色j香婷婷综合| 欧美在线综合| 久久综合色婷婷| 国产在线视频欧美一区二区三区| 午夜一区在线| 久久综合国产精品| 亚洲国产欧美一区二区三区同亚洲| 久久精品视频在线免费观看| 久久夜精品va视频免费观看| 国模套图日韩精品一区二区| 久久久成人网| 亚洲高清不卡av| 一区二区三区.www| 国产精品成人一区二区三区夜夜夜 | 久久国产主播精品| 狠狠久久综合婷婷不卡| 久久久人成影片一区二区三区观看| 葵司免费一区二区三区四区五区| 在线观看欧美视频| 久久久免费精品视频| 亚洲欧洲精品成人久久奇米网 | 亚洲精品男同| 国产精品精品视频| 欧美在线关看| 亚洲黑丝一区二区| 亚洲免费在线| 亚洲国产高清视频| 国际精品欧美精品| 欧美激情第9页| 亚洲欧美久久久久一区二区三区| 久久久久久久久久码影片| 亚洲国产99| 国产欧美一区二区三区视频| 久久午夜av| 亚洲夜间福利| 亚洲国产另类久久精品| 欧美一区二区三区久久精品茉莉花 | 午夜免费日韩视频| 亚洲电影一级黄| 欧美在线观看一区二区三区| 亚洲福利视频二区| 国产精品久久久久久影院8一贰佰| 久久精品官网| 亚洲无吗在线| 女同一区二区| 久久精品一区二区三区中文字幕| 亚洲精品1区| 国产欧美精品日韩区二区麻豆天美 | 亚洲欧美日韩国产综合精品二区| 欧美成va人片在线观看| 欧美一区二区三区免费观看视频| 亚洲激情在线观看视频免费| 国产香蕉久久精品综合网| 欧美日韩免费在线| 免费视频久久| 久久久噜噜噜| 久久精品欧美| 香蕉av777xxx色综合一区| aⅴ色国产欧美| 亚洲国产成人tv| 麻豆成人在线| 久久人人九九| 久久久久久一区二区| 欧美与欧洲交xxxx免费观看| 亚洲视频专区在线| 亚洲乱码国产乱码精品精天堂| 樱桃成人精品视频在线播放| 国产欧美日韩不卡免费| 欧美性猛交视频| 欧美日韩亚洲综合在线| 欧美激情视频给我| 欧美国产精品| 欧美极品色图| 欧美伦理91| 欧美日韩三级在线| 欧美日韩亚洲激情| 国产精品成人aaaaa网站| 欧美日韩理论| 国产精品久久久久国产a级| 欧美日精品一区视频| 欧美日韩在线观看一区二区三区| 欧美精品一区二区三区在线播放 | 久久婷婷综合激情| 六月丁香综合| 欧美激情五月| 99视频+国产日韩欧美| 在线视频中文亚洲| 午夜精品福利一区二区三区av | 亚洲高清色综合| 亚洲精品久久久久中文字幕欢迎你 | 蜜桃久久av一区| 欧美精品一区二区在线观看| 欧美日本中文字幕| 国产精品麻豆va在线播放| 国产欧美日韩中文字幕在线| 国产一区久久久| 亚洲国产一区二区视频| 一本大道久久精品懂色aⅴ| 一区二区久久久久| 午夜精品福利在线观看| 久久综合伊人| 亚洲精品中文字幕有码专区| 亚洲一区二区久久| 久久久国产一区二区| 欧美极品一区| 免费看成人av| 久久久一本精品99久久精品66| 久久最新视频| 亚洲精品日韩久久| 欧美在线播放一区二区| 欧美成人午夜激情在线| 国产精品视频不卡| 亚洲国产精品成人综合| 你懂的国产精品永久在线| 免费高清在线视频一区·| 日韩亚洲在线观看| 久久久久成人精品| 国产精品大片wwwwww| 伊人久久av导航| 亚洲欧美中日韩| 亚洲国产精品va在看黑人| 亚洲欧美中文日韩在线| 欧美精品一二三| 永久域名在线精品| 欧美亚洲视频| 亚洲精品久久久久久久久久久久 | 午夜一区二区三视频在线观看| 欧美国产第一页| 精品成人一区二区三区| 亚洲欧美大片| 亚洲三级毛片| 免费在线观看一区二区| 国产一区自拍视频| 午夜免费日韩视频| 一本色道久久88综合日韩精品| 男女精品网站| 伊人精品成人久久综合软件|