21856_MilleniumLeapcow

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

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

Pro.ID

21856

Title

Millenium Leapcow

Title链接

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

AC

0

Submit

0

Ratio

-

时间&空间限制

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

    The cows have revised their game of leapcow. They now play in the middle of a huge pasture upon which they have marked a grid that bears a remarkable resemblance to a chessboard of N rows and N columns ( 3 ≤ N ≤ 365 ).

    Here's how they set up the board for the new leapcow game:

    * First, the cows obtain N × N squares of paper. They write the integers from 1 through N × N, one number on each piece of paper.

    * Second, the 'number cow' places the papers on the N × N squares in an order of her choosing.

    Each of the remaining cows then tries to maximize her score in the game.

    * First, she chooses a starting square and notes its number.

    * Then, she makes a 'knight' move (like the knight on a chess board) to a square with a higher number. If she's particularly strong, she leaps to the that square; otherwise she walks.

    * She continues to make 'knight' moves to higher numbered squares until no more moves are possible.

    Each square visited by the 'knight' earns the competitor a single point. The cow with the most points wins the game.

    Help the cows figure out the best possible way to play the game.

    输入

    * Line 1: A single integer: the size of the board

    * Lines 2.. ...: These lines contain space-separated integers that tell the contents of the chessboard. The first set of lines (starting at the second line of the input file) represents the first row on the chessboard; the next set of lines represents the next row, and so on. To keep the input lines of reasonable length, when N > 15, a row is broken into successive lines of 15 numbers and a potentially shorter line to finish up a row. Each new row begins on its own line.

    输出

    Description

    The cows have revised their game of leapcow. They now play in the middle of a huge pasture upon which they have marked a grid that bears a remarkable resemblance to a chessboard of N rows and N columns ( 3 ≤ N ≤ 365 ).

    Here's how they set up the board for the new leapcow game:

    * First, the cows obtain N × N squares of paper. They write the integers from 1 through N × N, one number on each piece of paper.

    * Second, the 'number cow' places the papers on the N × N squares in an order of her choosing.

    Each of the remaining cows then tries to maximize her score in the game.

    * First, she chooses a starting square and notes its number.

    * Then, she makes a 'knight' move (like the knight on a chess board) to a square with a higher number. If she's particularly strong, she leaps to the that square; otherwise she walks.

    * She continues to make 'knight' moves to higher numbered squares until no more moves are possible.

    Each square visited by the 'knight' earns the competitor a single point. The cow with the most points wins the game.

    Help the cows figure out the best possible way to play the game.

    Input

    * Line 1: A single integer: the size of the board

    * Lines 2.. ...: These lines contain space-separated integers that tell the contents of the chessboard. The first set of lines (starting at the second line of the input file) represents the first row on the chessboard; the next set of lines represents the next row, and so on. To keep the input lines of reasonable length, when N > 15, a row is broken into successive lines of 15 numbers and a potentially shorter line to finish up a row. Each new row begins on its own line.

    Output

    * Line 1: A single integer that is the winning cow's score; call it W.

    * Lines 2..W+1: Output, one per line, the integers that are the starting square, the next square the winning cow visits, and so on through the last square. If a winning cow can choose more than one path, show the path that would be the 'smallest' if the paths were sorted by comparing their respective 'square numbers'.

    Sample Input

    4
    1 3 2 16
    4 10 6 7
    8 11 5 12
    9 13 14 15

    Sample Output

    7
    2
    4
    5
    9
    10
    12
    13

    Source

    样例输入

    4
    1 3 2 16
    4 10 6 7
    8 11 5 12
    9 13 14 15

    样例输出

    7
    2
    4
    5
    9
    10
    12
    13

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部