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

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個(gè)國(guó)王和若干個(gè)騎士,要把國(guó)王和每個(gè)騎士移動(dòng)到同一個(gè)格子內(nèi),問需要移動(dòng)的最小步數(shù)是多少。如果國(guó)王和騎士走到同一個(gè)格子里,可以由騎士帶著國(guó)王一起移動(dòng)。
    枚舉棋盤上的64個(gè)點(diǎn)作為終點(diǎn),對(duì)于每一個(gè)假定的終點(diǎn),再枚舉這64個(gè)點(diǎn)作為國(guó)王和某個(gè)騎士相遇的點(diǎn),最后求出需要移動(dòng)的最小步數(shù)。其中根據(jù)騎士和國(guó)王移動(dòng)的特點(diǎn)可以預(yù)處理出從1個(gè)點(diǎn)到另外1個(gè)點(diǎn)所需的最小移動(dòng)次數(shù),也可用搜索。
#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 極限定律 閱讀(2371) 評(píng)論(0)  編輯 收藏 引用 所屬分類: ACM/ICPC

<2009年4月>
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

導(dǎo)航

統(tǒng)計(jì)

常用鏈接

留言簿(10)

隨筆分類

隨筆檔案

友情鏈接

搜索

最新評(píng)論

閱讀排行榜

評(píng)論排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            欧美/亚洲一区| 亚洲欧美国产精品va在线观看| 欧美尤物巨大精品爽| 欧美小视频在线| 宅男精品视频| 亚洲一区二区三区在线视频| 国产精品毛片在线| 欧美在线免费观看视频| 欧美亚洲视频在线观看| 黄色亚洲在线| 亚洲国产高清一区二区三区| 欧美国产视频一区二区| 亚洲视频视频在线| 亚洲免费一区二区| 伊人久久综合| 亚洲精品午夜精品| 国产乱码精品1区2区3区| 久久久噜噜噜久噜久久| 男人插女人欧美| 亚洲视屏在线播放| 亚洲欧美日韩精品久久| 亚洲电影中文字幕| 在线视频精品一区| 在线播放精品| av成人天堂| 在线成人小视频| 一本色道久久综合亚洲精品按摩| 国产午夜亚洲精品羞羞网站| 欧美成人精品不卡视频在线观看| 欧美日韩国产高清| 久久久久久久综合日本| 欧美日韩成人在线播放| 久久久在线视频| 国产精品久99| 亚洲人成人一区二区在线观看| 国产精品青草综合久久久久99| 免费成人av在线看| 国产精品久久久久久福利一牛影视 | 欧美成人一区二区在线| 亚洲欧美日本国产有色| 免费观看不卡av| 久久精品视频在线播放| 欧美区二区三区| 欧美aa在线视频| 国产日本精品| 一区二区三区毛片| 99精品国产福利在线观看免费 | 亚洲国产一区二区三区a毛片| 国产欧美日韩视频| 亚洲美女视频| 亚洲人成亚洲人成在线观看| 欧美亚洲综合另类| 亚洲免费伊人电影在线观看av| 欧美3dxxxxhd| 免费成人黄色| 一区二区三区在线不卡| 亚洲小说区图片区| 亚洲午夜三级在线| 欧美日韩一区二区三区四区在线观看| 乱中年女人伦av一区二区| 国产午夜精品理论片a级探花| 99精品国产在热久久下载| 日韩视频永久免费| 欧美激情综合色综合啪啪| 欧美国产日韩xxxxx| 在线观看国产欧美| 久久久久久久尹人综合网亚洲| 欧美一区亚洲| 国产欧美一区二区三区在线看蜜臀| 一区二区三区免费看| 亚洲午夜精品久久| 欧美日韩国产免费观看| 99一区二区| 亚洲一区二区免费| 国产精品视频999| 亚洲主播在线| 久久伊人亚洲| 在线日韩视频| 欧美成人免费网站| 日韩午夜在线视频| 亚洲欧美日韩国产一区二区三区 | 亚洲自拍都市欧美小说| 午夜精品www| 国产一区二区三区久久久久久久久| 亚洲综合成人婷婷小说| 久久精品亚洲乱码伦伦中文| 国产在线不卡精品| 老司机午夜精品视频| 亚洲欧洲日本专区| 亚洲综合不卡| 国产一区二区av| 嫩模写真一区二区三区三州| 亚洲黄色一区| 亚洲欧美一区二区精品久久久| 国产情侣一区| 免费久久精品视频| 一区二区三区四区蜜桃| 久久精品亚洲精品| 日韩视频专区| 国产拍揄自揄精品视频麻豆| 久久综合亚洲社区| 一本色道88久久加勒比精品 | 99精品视频免费全部在线| 欧美三级第一页| 久久精品亚洲乱码伦伦中文| 亚洲国产欧美国产综合一区| 亚洲欧美国产日韩天堂区| 黄色亚洲网站| 国产精品爱久久久久久久| 欧美在线免费视屏| 9色精品在线| 老牛嫩草一区二区三区日本| aaa亚洲精品一二三区| 国内外成人免费激情在线视频| 欧美国产一区二区| 欧美中文日韩| 在线一区二区视频| 亚洲高清久久网| 久久成人免费| 亚洲在线一区二区| 亚洲日韩视频| 伊人久久大香线蕉综合热线 | 欧美大片18| 久久精品日韩欧美| 亚洲欧美网站| 99精品国产一区二区青青牛奶| 欧美+亚洲+精品+三区| 午夜精品视频在线观看| 夜夜嗨av一区二区三区四区 | 欧美午夜不卡影院在线观看完整版免费| 欧美在线视频观看| 亚洲一区二区久久| 99视频精品全国免费| 亚洲国产乱码最新视频| 美女福利精品视频| 久久免费午夜影院| 久久精品在线观看| 久久精品视频导航| 久久高清免费观看| 久久se精品一区二区| 亚洲欧美日韩天堂| 亚洲综合清纯丝袜自拍| 亚洲一区二区三区精品在线| 在线视频欧美一区| 一道本一区二区| 在线视频欧美日韩| 在线视频亚洲欧美| 亚洲一级在线观看| 亚洲一区在线观看免费观看电影高清| 日韩一级二级三级| 中国成人在线视频| 亚洲综合导航| 欧美一区二区三区免费看| 久久国产一区| 六月婷婷一区| 欧美激情一区二区在线 | 欧美国产三级| 亚洲观看高清完整版在线观看| 亚洲盗摄视频| 亚洲美女少妇无套啪啪呻吟| 99这里只有精品| 亚洲免费视频在线观看| 欧美一区日韩一区| 久久嫩草精品久久久久| 欧美成人精品影院| 欧美日韩一区三区| 国产精品一区二区三区乱码| 国产一区二区丝袜高跟鞋图片| 国语自产偷拍精品视频偷| 亚洲国产一二三| 日韩午夜在线播放| 香蕉国产精品偷在线观看不卡| 欧美在线观看视频一区二区| 久久一区视频| 亚洲精品国产无天堂网2021| 99精品视频免费全部在线| 亚洲欧美久久| 久久综合久久综合久久综合| 欧美日韩国产综合新一区| 国产精品一区二区三区乱码| 一区久久精品| 亚洲一区免费网站| 久久午夜精品一区二区| 亚洲国产综合在线看不卡| 亚洲一区国产| 久久综合激情| 国产精品免费在线 | 国产精品地址| 在线国产亚洲欧美| 亚洲自拍偷拍一区| 欧美成人精品高清在线播放| 一区二区三区视频免费在线观看| 久久av二区| 欧美亚州韩日在线看免费版国语版| 国模大胆一区二区三区| 在线中文字幕一区| 女人天堂亚洲aⅴ在线观看| 亚洲丝袜av一区| 欧美美女操人视频| 在线看欧美视频|