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

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


    棋盤(pán)上有1個(gè)國(guó)王和若干個(gè)騎士,要把國(guó)王和每個(gè)騎士移動(dòng)到同一個(gè)格子內(nèi),問(wèn)需要移動(dòng)的最小步數(shù)是多少。如果國(guó)王和騎士走到同一個(gè)格子里,可以由騎士帶著國(guó)王一起移動(dòng)。
    枚舉棋盤(pán)上的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 極限定律 閱讀(2374) 評(píng)論(0)  編輯 收藏 引用 所屬分類(lèi): ACM/ICPC

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

導(dǎo)航

統(tǒng)計(jì)

常用鏈接

留言簿(10)

隨筆分類(lèi)

隨筆檔案

友情鏈接

搜索

最新評(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>
            欧美激情综合色| 久久久精品午夜少妇| 国产综合色一区二区三区 | 99re成人精品视频| 国产亚洲一二三区| 欧美小视频在线| 欧美91视频| 久久精品国语| 午夜一区二区三区不卡视频| 亚洲精品美女久久7777777| 久久夜色精品国产| 久久国产精品亚洲77777| 亚洲图片在线观看| 99精品99久久久久久宅男| 亚洲国产成人av好男人在线观看| 国产精品有限公司| 国产精品久久久亚洲一区 | 宅男噜噜噜66一区二区| 亚洲日本成人在线观看| 亚洲电影第三页| 狠狠色丁香久久婷婷综合_中| 国产精品免费观看视频| 国产精品国产| 欧美色综合网| 欧美午夜精品久久久久久超碰| 欧美国产日韩a欧美在线观看| 老司机久久99久久精品播放免费| 欧美影院成年免费版| 先锋资源久久| 欧美与黑人午夜性猛交久久久| 亚洲欧美日韩在线播放| 亚洲欧美日韩综合aⅴ视频| 亚洲在线播放| 午夜精品理论片| 性色av一区二区三区| 亚欧成人精品| 久久久久久伊人| 久久字幕精品一区| 美女精品视频一区| 欧美乱大交xxxxx| 欧美日韩在线观看视频| 欧美午夜一区二区福利视频| 国产精品国产三级国产专播品爱网 | 欧美三级视频在线播放| 欧美视频在线免费| 国产精品影视天天线| 国产日产亚洲精品系列| 精品成人在线观看| 最近中文字幕mv在线一区二区三区四区| 亚洲激情另类| 亚洲性感激情| 久久精品官网| 免费视频一区| 日韩视频在线你懂得| 亚洲一区二区三区免费视频| 欧美亚洲一区在线| 麻豆成人在线观看| 欧美日韩理论| 国产欧美亚洲视频| 亚洲电影毛片| 亚洲一区二区精品视频| 久久国产精品一区二区| 欧美成人第一页| 日韩午夜在线观看视频| 欧美亚洲自偷自偷| 欧美不卡视频一区| 国产精品女主播| 亚洲国产精品免费| 亚洲永久字幕| 欧美18av| 亚洲一区在线直播| 免费观看久久久4p| 国产精品亚洲第一区在线暖暖韩国| 国际精品欧美精品| 一区二区久久久久久| 久久久久网站| 日韩视频在线观看国产| 久久精品论坛| 欧美手机在线| 亚洲国产日韩在线一区模特| 亚洲视频导航| 欧美福利专区| 亚洲欧美日韩中文播放| 欧美精品999| 狠狠狠色丁香婷婷综合激情| 中文一区字幕| 欧美国产欧美综合 | 欧美激情一区二区| 国产亚洲一区二区在线观看| 一区二区久久久久| 免费一级欧美片在线观看| 亚洲午夜高清视频| 欧美大片在线影院| 韩国免费一区| 欧美一站二站| 一本久久综合亚洲鲁鲁五月天| 久久夜色精品国产欧美乱| 国产精品亚洲欧美| 在线天堂一区av电影| 欧美国产视频一区二区| 欧美在线首页| 国产精品性做久久久久久| 一区二区三区免费观看| 欧美国产先锋| 久久久久免费观看| 国产一区二区av| 欧美一区二区黄色| 在线视频亚洲| 欧美三级资源在线| 9i看片成人免费高清| 欧美激情在线观看| 久久女同互慰一区二区三区| 国产日韩亚洲| 久久超碰97人人做人人爱| 亚洲视频1区2区| 欧美日韩在线播放一区| 9久re热视频在线精品| 欧美黄色一级视频| 另类激情亚洲| 亚洲电影天堂av| 欧美成人免费观看| 久久五月激情| 亚洲国产日日夜夜| 亚洲大片av| 欧美—级高清免费播放| 亚洲精品免费在线播放| 亚洲第一毛片| 欧美寡妇偷汉性猛交| 日韩午夜av电影| 亚洲精品在线一区二区| 欧美日韩ab片| 亚洲伊人网站| 亚洲欧美精品| 韩国一区二区在线观看| 久久中文欧美| 美女任你摸久久| 亚洲精品在线三区| 亚洲美女尤物影院| 国产精品国码视频| 欧美在线播放高清精品| 欧美影院成人| 亚洲国产va精品久久久不卡综合| 欧美国产日韩一区二区在线观看 | 亚洲一本视频| 亚洲综合成人在线| 国产亚洲成精品久久| 久久久亚洲国产天美传媒修理工| 久久er99精品| 亚洲激情专区| 夜夜嗨一区二区| 国产日韩欧美不卡| 美女免费视频一区| 欧美精品v日韩精品v国产精品| 在线视频精品一区| 亚洲欧美视频一区| 伊人久久婷婷| 亚洲每日在线| 国产欧美一区二区三区沐欲 | 国语自产偷拍精品视频偷| 免费成人激情视频| 欧美人与性禽动交情品| 午夜精品国产| 久久久久久尹人网香蕉| 一区二区不卡在线视频 午夜欧美不卡在 | 欧美成年人视频网站欧美| 国产精品99久久99久久久二8| 亚洲自拍16p| 亚洲国产精品一区制服丝袜| 99国内精品久久久久久久软件| 国产欧美日本一区视频| 亚洲成色777777女色窝| 欧美激情精品久久久久久蜜臀| 欧美国产亚洲视频| 欧美一进一出视频| 欧美电影在线免费观看网站| 亚洲在线视频一区| 狂野欧美激情性xxxx欧美| 亚洲一区图片| 蜜臀av性久久久久蜜臀aⅴ四虎| 亚洲欧美国产日韩天堂区| 久久一区二区三区四区五区| 亚洲伊人色欲综合网| 狂野欧美激情性xxxx欧美| 性欧美video另类hd性玩具| 免费日韩一区二区| 久久精品免费看| 欧美日韩免费网站| 久久亚洲精选| 国产精品毛片一区二区三区| 欧美激情女人20p| 国产午夜精品麻豆| av成人老司机| 最新高清无码专区| 久久福利电影| 午夜精品av| 欧美日韩在线播放三区| 欧美激情无毛| 极品尤物av久久免费看| 亚洲欧美日韩精品久久久久| 一级日韩一区在线观看|