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

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 極限定律 閱讀(2376) 評論(0)  編輯 收藏 引用 所屬分類: ACM/ICPC

<2025年12月>
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

導航

統計

常用鏈接

留言簿(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>
            欧美美女操人视频| 亚洲视频在线观看一区| 久久久999精品视频| 国产精品亚洲成人| 午夜精品一区二区在线观看| 亚洲深夜av| 国产精品天天摸av网| 午夜精品美女自拍福到在线| 中文av一区二区| 国产欧美91| 免费成人黄色av| 免费日韩视频| 亚洲网在线观看| 亚洲一区二区三区中文字幕 | 亚洲精品日本| 国产精品激情偷乱一区二区∴| 性色av一区二区三区在线观看| 午夜精品视频在线观看一区二区| 国内精品视频在线播放| 亚洲高清视频中文字幕| 欧美精品v国产精品v日韩精品| 中文精品视频| 午夜精品一区二区三区在线| 悠悠资源网久久精品| 亚洲精品欧美日韩专区| 国产欧美精品一区aⅴ影院| 欧美成人亚洲成人日韩成人| 欧美日韩色综合| 久久青青草原一区二区| 欧美久久九九| 美国成人直播| 国产精品激情电影| 欧美激情精品久久久久| 国产精品大片| 亚洲国产国产亚洲一二三| 国产精品久久久久久久7电影| 免费观看成人网| 国产精品久久久久av免费| 欧美成人精品福利| 国产日韩一区二区三区在线播放 | 久久婷婷国产综合尤物精品| 免费观看成人| 久久国产精品99久久久久久老狼 | 亚洲一区二区三区精品在线| 黄色在线一区| 亚洲私人影院| 99re在线精品| 久久综合久久美利坚合众国| 久久成人久久爱| 欧美日韩成人综合| 欧美aⅴ一区二区三区视频| 国产欧美日韩专区发布| 亚洲久久成人| 亚洲欧洲日产国产网站| 久久网站免费| 久久精品一区二区三区中文字幕| 欧美午夜美女看片| 99精品国产热久久91蜜凸| 亚洲激情校园春色| 久久精品中文字幕一区二区三区| 先锋资源久久| 国产精品一区二区黑丝| 亚洲午夜精品一区二区三区他趣| 亚洲精品久久久久久久久久久久久 | 亚洲日本国产| 蜜臀久久99精品久久久久久9| 麻豆精品传媒视频| 激情久久五月| 久久青草欧美一区二区三区| 久久人人97超碰精品888| 国产在线欧美| 久久精品99国产精品酒店日本| 久久久夜精品| 在线精品国精品国产尤物884a| 久久精品人人做人人爽| 美女精品国产| 亚洲人体偷拍| 欧美日韩亚洲综合在线| 亚洲午夜久久久久久久久电影网| 亚洲欧美在线磁力| 国产一区二区黄| 久久在线视频在线| 亚洲国产精品v| 夜夜狂射影院欧美极品| 国产精品久久久久久久午夜| 亚洲性感美女99在线| 久久久精品视频成人| 在线看国产一区| 欧美电影免费观看大全| 日韩一区二区精品在线观看| 午夜激情一区| 亚洲承认在线| 欧美日一区二区在线观看| 亚洲欧美999| 蘑菇福利视频一区播放| 日韩视频一区二区三区| 国产精品高潮呻吟| 欧美亚洲三区| 91久久精品日日躁夜夜躁欧美 | 国产欧美丝祙| 久久一区二区三区四区| 日韩亚洲一区二区| 久久全球大尺度高清视频| 亚洲精品婷婷| 国产色产综合色产在线视频| 老司机精品视频网站| 亚洲一区二区精品| 男人的天堂亚洲在线| 亚洲一区二区三区午夜| 精品动漫3d一区二区三区免费| 免费日韩视频| 欧美一区二区高清| 日韩视频在线观看国产| 久久免费视频一区| 亚洲天堂黄色| 亚洲精品自在在线观看| 国产综合av| 国产精品久久久久婷婷| 欧美国产免费| 久久久久青草大香线综合精品| 夜夜嗨av一区二区三区四区| 欧美成人官网二区| 久久久xxx| 午夜精品视频网站| 日韩一区二区久久| 亚洲国产精品一区制服丝袜| 国产免费观看久久| 欧美日韩欧美一区二区| 欧美成人精品激情在线观看 | 欧美激情精品久久久六区热门| 久久成人精品电影| 亚洲欧美激情精品一区二区| 日韩一级精品| 亚洲日韩中文字幕在线播放| 尤物九九久久国产精品的分类| 国产欧美日韩另类一区| 国产精品久久久久久久午夜片 | 久久精品成人一区二区三区蜜臀 | 亚洲国产小视频| 欧美不卡视频一区发布| 久久精品国产综合精品| 欧美一区三区三区高中清蜜桃| 亚洲午夜成aⅴ人片| a91a精品视频在线观看| 99精品欧美一区二区蜜桃免费| 亚洲激情av在线| 最新国产成人在线观看| 91久久精品日日躁夜夜躁国产| 亚洲成色777777在线观看影院 | 欧美精品三级日韩久久| 男人天堂欧美日韩| 欧美成人性网| 欧美日韩国产综合在线| 国产精品高潮呻吟久久av黑人| 欧美日韩一区二区三区四区五区| 欧美精品一区二区三区四区 | 久久岛国电影| 久久视频在线免费观看| 久久亚洲美女| 免费一级欧美片在线观看| 欧美fxxxxxx另类| 欧美日韩免费高清一区色橹橹| 欧美日精品一区视频| 国产麻豆精品theporn| 国产一级精品aaaaa看| 在线观看日韩欧美| 亚洲美女尤物影院| 亚洲专区一二三| 久久狠狠亚洲综合| 欧美福利影院| 日韩视频免费大全中文字幕| 亚洲午夜在线观看视频在线| 欧美在线视频观看免费网站| 久久亚洲美女| 国产精品v欧美精品v日韩 | 欧美日精品一区视频| 国产精品综合| 99pao成人国产永久免费视频| 亚洲天天影视| 久久久999| 亚洲国产合集| 午夜精品免费视频| 久久欧美中文字幕| 欧美性大战久久久久| 国产偷国产偷精品高清尤物| 亚洲国产精品传媒在线观看| 中日韩午夜理伦电影免费| 久久久久久一区二区三区| 亚洲人成人99网站| 午夜精品亚洲一区二区三区嫩草| 免费不卡亚洲欧美| 国产精品香蕉在线观看| 亚洲精品中文字幕有码专区| 欧美中文字幕| 99精品视频网| 美女诱惑一区| 国产视频精品va久久久久久| av成人国产| 欧美激情91| 欧美一区二区三区精品|