10167_Camelo

2022-5-16 18:16| 发布者: Hocassian| 查看: 65| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-3-89504622082100-Problem List-采集的数据-后羿采集器.html

Pro.ID

10167

Title

Camelot

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=10167

AC

4

Submit

46

Ratio

8.70%

时间&空间限制

  • Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    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 chesspiece king and several knight pieces are placed on squares, no two knights on the same square.

    This example board is the standard 8×8 array of squares:

    The King can move to any adjacent square from to as long as it does not fall off the board:

    A Knight can jump from to , 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 any other piece to move freely.

    The player's goal is to move the pieces so as to gather them all in the same square -- in the minimal 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 from that point on, 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. The pieces can gather on any square, of course.

    输入

    Multiple test cases. For each case:

    Line 1:  Two space-separated integers: R, C, the number of rows and columns on the board. There will be no more than 26 columns and no more than 30 rows.

    Line 2..:  The input file contains a sequence of space-separated letter/digit pairs, 1 or more per line. The first pair represents the board position of the king; subsequent pairs represent positions of knights. There might be 0 knights or the knights might fill the board. Rows are numbered starting at 1; columns are specified as upper case characters starting with 'A'.

    The line contains only '~' ends a test case.

    输出

    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 chesspiece king and several knight pieces are placed on squares, no two knights on the same square.

    This example board is the standard 8×8 array of squares:

    The King can move to any adjacent square from to as long as it does not fall off the board:

    A Knight can jump from to , 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 any other piece to move freely.

    The player's goal is to move the pieces so as to gather them all in the same square -- in the minimal 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 from that point on, 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. The pieces can gather on any square, of course.

    Input

    Multiple test cases. For each case:

    Line 1:  Two space-separated integers: R, C, the number of rows and columns on the board. There will be no more than 26 columns and no more than 30 rows.

    Line 2..:  The input file contains a sequence of space-separated letter/digit pairs, 1 or more per line. The first pair represents the board position of the king; subsequent pairs represent positions of knights. There might be 0 knights or the knights might fill the board. Rows are numbered starting at 1; columns are specified as upper case characters starting with 'A'.

    The line contains only '~' ends a test case.

    Output

    For each case, output a single line with the number of moves to aggregate the pieces.

    Sample Input

    8 8
    D 4
    A 3 A 8
    H 1 H 8
    ~

    Sample Output

    10

    Hint

    Sample Input:

    The king is positioned at D4. There are four knights, positioned at A3, A8, H1, and H8.

    Sample Output:

    They gather at B5.

    Knight 1: A3 - B5 (1 move)

    Knight 2: A8 - C7 - B5 (2 moves)

    Knight 3: H1 - G3 - F5 - D4 (picking up king) - B5 (4 moves)

    Knight 4: H8 - F7 - D6 - B5 (3 moves)

    1 + 2 + 4 + 3 = 10 moves.

    Source

    样例输入

    8 8
    D 4
    A 3 A 8
    H 1 H 8
    ~

    样例输出

    10

    提示

    Sample Input:

    The king is positioned at D4. There are four knights, positioned at A3, A8, H1, and H8.

    Sample Output:

    They gather at B5.

    Knight 1: A3 - B5 (1 move)

    Knight 2: A8 - C7 - B5 (2 moves)

    Knight 3: H1 - G3 - F5 - D4 (picking up king) - B5 (4 moves)

    Knight 4: H8 - F7 - D6 - B5 (3 moves)

    1 + 2 + 4 + 3 = 10 moves.


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部