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

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>
            亚洲欧美日韩精品久久亚洲区| 亚洲欧美日韩国产成人| 久久亚洲国产成人| 久久九九久久九九| 亚洲电影在线免费观看| 亚洲国产裸拍裸体视频在线观看乱了| 久久夜色精品| 亚洲美女中出| 亚洲欧美另类中文字幕| 韩曰欧美视频免费观看| 欧美成人精品激情在线观看| 欧美大片免费久久精品三p| 在线一区视频| 欧美亚洲尤物久久| 亚洲欧洲日韩女同| 一区二区高清视频| 韩国成人福利片在线播放| 媚黑女一区二区| 欧美日韩国产精品一卡| 欧美在线中文字幕| 欧美成人一品| 久久99在线观看| 欧美99久久| 欧美一级久久久久久久大片| 久久人人看视频| 亚洲亚洲精品三区日韩精品在线视频 | 欧美日韩小视频| 久久精品30| 欧美日韩成人综合| 久久久久久69| 欧美午夜电影一区| 老牛嫩草一区二区三区日本| 欧美日韩国产美| 另类专区欧美制服同性| 国产精品白丝黑袜喷水久久久| 久久久久久午夜| 欧美午夜在线观看| 亚洲国产成人不卡| 怡红院av一区二区三区| 亚洲一区二区三区四区在线观看| **网站欧美大片在线观看| 在线综合+亚洲+欧美中文字幕| 亚洲第一在线综合在线| 午夜久久久久久| 亚洲男人第一av网站| 欧美护士18xxxxhd| 免费不卡在线观看av| 国产欧美视频一区二区三区| 夜夜夜久久久| 亚洲精品一二三| 麻豆成人av| 免费不卡在线观看| 国产资源精品在线观看| 亚洲伊人一本大道中文字幕| 在线一区观看| 欧美激情性爽国产精品17p| 麻豆乱码国产一区二区三区| 国产午夜精品美女毛片视频| 亚洲天堂男人| 午夜视频在线观看一区二区三区 | 亚洲精品一区二| 亚洲区第一页| 欧美韩国在线| 亚洲精品免费在线| 一本一本a久久| 欧美欧美午夜aⅴ在线观看| 亚洲国产91色在线| 日韩一级网站| 欧美午夜精品理论片a级按摩| 亚洲国产专区校园欧美| 999亚洲国产精| 欧美日韩一区二区三区免费| 在线视频精品一区| 亚洲免费视频一区二区| 国产精品高清一区二区三区| 亚洲一区二区三区四区中文| 欧美与欧洲交xxxx免费观看 | 久久黄金**| 每日更新成人在线视频| 一区在线免费| 欧美激情国产日韩| 亚洲每日更新| 欧美一区1区三区3区公司| 国产日韩在线一区二区三区| 久久久久99| 亚洲日本成人| 欧美一区二区三区四区在线观看地址 | 亚洲国产美国国产综合一区二区| 亚洲精品精选| 国产精品久久久久久久久久尿| 午夜在线精品| 91久久精品国产91性色| 亚洲专区一区| 亚洲高清不卡在线观看| 欧美伦理91i| 欧美一区二区精美| 亚洲国产日韩综合一区| 亚洲欧美日韩国产成人精品影院 | 欧美三级特黄| 欧美在线一区二区| 欧美国产综合视频| 欧美亚洲午夜视频在线观看| 激情成人亚洲| 欧美三级视频在线播放| 欧美在线综合| 亚洲深爱激情| 亚洲高清视频在线观看| 亚洲欧美日韩一区二区| 亚洲国产午夜| 国产日韩一区二区三区| 欧美日韩裸体免费视频| 久久亚洲精选| 午夜日韩在线观看| 亚洲人成网站999久久久综合| 久久激情久久| 亚洲欧美国产精品桃花| 亚洲激情一区二区| 国产欧美一区二区三区在线看蜜臀| 久久久久www| 亚洲午夜久久久久久久久电影院 | 午夜精品福利一区二区三区av| 亚洲高清不卡在线| 国产拍揄自揄精品视频麻豆| 欧美日韩大片一区二区三区| 久久在精品线影院精品国产| 亚洲你懂的在线视频| 亚洲人成人一区二区三区| 久久精品噜噜噜成人av农村| 亚洲欧美日本视频在线观看| 亚洲免费观看高清完整版在线观看熊 | 日韩视频一区二区三区| 国产在线国偷精品产拍免费yy| 欧美午夜美女看片| 欧美日韩国产高清| 欧美国产欧美亚州国产日韩mv天天看完整| 欧美一区二区视频97| 亚洲一区欧美| 亚洲精品日韩精品| 欧美激情精品久久久久久久变态 | 亚洲一区二区网站| 一区二区三区四区五区视频| 亚洲国产精品一区| 亚洲电影有码| 亚洲黑丝在线| 亚洲精品免费电影| 亚洲人成高清| 日韩视频一区二区三区| 亚洲免费av片| 亚洲少妇诱惑| 午夜精品亚洲| 久久九九免费视频| 久久久精品一区| 美女精品自拍一二三四| 美女精品视频一区| 欧美夫妇交换俱乐部在线观看| 欧美福利精品| 亚洲精品美女久久久久| 日韩图片一区| 亚洲欧美亚洲| 久久久夜色精品亚洲| 裸体歌舞表演一区二区| 欧美国产综合视频| 欧美日一区二区三区在线观看国产免| 欧美日韩国产三区| 国产精品麻豆欧美日韩ww| 国产日韩欧美麻豆| 亚洲电影免费在线| 亚洲精品老司机| 亚洲欧美日本另类| 久久综合成人精品亚洲另类欧美| 欧美第一黄色网| 一区二区三区日韩| 久久国产加勒比精品无码| 欧美91福利在线观看| 欧美日韩在线三区| 国产主播一区二区三区| 99精品国产在热久久婷婷| 亚洲欧美日韩综合国产aⅴ| 久久久在线视频| 亚洲免费观看| 久久久久久尹人网香蕉| 欧美高清在线精品一区| 国产精品视频最多的网站| 亚洲韩国青草视频| 欧美亚洲视频在线观看| 欧美激情2020午夜免费观看| 亚洲色诱最新| 欧美大尺度在线| 国产性猛交xxxx免费看久久| 亚洲美女啪啪| 美女脱光内衣内裤视频久久影院 | 亚洲区欧美区| 久久精品国产91精品亚洲| 欧美日韩一区在线| 樱桃成人精品视频在线播放| 午夜精品久久| 亚洲美女啪啪| 欧美国产日韩a欧美在线观看| 国产亚洲欧洲997久久综合| 亚洲一区二区免费|