22527_TheWormTurns

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

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

Pro.ID

22527

Title

The Worm Turns

Title链接

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

AC

0

Submit

0

Ratio

-

时间&空间限制

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

    Worm is an old computer game. There are many versions, but all involve maneuvering a "worm" around the screen, trying to avoid running the worm into itself or an obstacle.

    We'll simulate a very simplified version here. The game will be played on a 50 x 50 board, numbered so that the square at the upper left is numbered (1, 1). The worm is initially a string of 20 connected squares. Connected squares are adjacent horizontally or vertically. The worm starts stretched out horizontally in positions (25, 11) through (25, 30), with the head of the worm at (25, 30). The worm can move either East (E), West (W), North (N) or South (S), but will never move back on itself. So, in the initial position, a W move is not possible. Thus the only two squares occupied by the worm that change in any move are its head and tail. Note that the head of the worm can move to the square just vacated by the worm's tail.

    You will be given a series of moves and will simulate the moves until either the worm runs into itself, the worm runs off the board, or the worm successfully negotiates its list of moves. In the first two cases you should ignore the remaining moves in the list.

    输入

    There will be multiple problems instances. The input for each problem instance will be on two lines. The first line is an integer n ( < 100 ) indicating the number of moves to follow. ( A value of n = 0 indicates end of input. ) The next line contains n characters ( either E, W, N or S ), with no spaces separating the letters, indicating the sequence of moves.

    输出

    Description

    Worm is an old computer game. There are many versions, but all involve maneuvering a "worm" around the screen, trying to avoid running the worm into itself or an obstacle.

    We'll simulate a very simplified version here. The game will be played on a 50 x 50 board, numbered so that the square at the upper left is numbered (1, 1). The worm is initially a string of 20 connected squares. Connected squares are adjacent horizontally or vertically. The worm starts stretched out horizontally in positions (25, 11) through (25, 30), with the head of the worm at (25, 30). The worm can move either East (E), West (W), North (N) or South (S), but will never move back on itself. So, in the initial position, a W move is not possible. Thus the only two squares occupied by the worm that change in any move are its head and tail. Note that the head of the worm can move to the square just vacated by the worm's tail.

    You will be given a series of moves and will simulate the moves until either the worm runs into itself, the worm runs off the board, or the worm successfully negotiates its list of moves. In the first two cases you should ignore the remaining moves in the list.

    Input

    There will be multiple problems instances. The input for each problem instance will be on two lines. The first line is an integer n ( < 100 ) indicating the number of moves to follow. ( A value of n = 0 indicates end of input. ) The next line contains n characters ( either E, W, N or S ), with no spaces separating the letters, indicating the sequence of moves.

    Output

    Generate one line of output for each problem instance. The output line should be one of the follow three:

    The worm ran into itself on move m.
    The worm ran off the board on move m.
    The worm successfully made all m moves.

    Where m is for you to determine and the first move is move 1.

    Sample Input

    18
    NWWWWWWWWWWSESSSWS
    20
    SSSWWNENNNNNWWWWSSSS
    30
    EEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
    13
    SWWWWWWWWWNEE0

    Sample Output

    The worm successfully made all 18 moves.
    The worm ran into itself on move 9.
    The worm ran off the board on move 21.
    The worm successfully made all 13 moves.

    Source

    样例输入

    18
    NWWWWWWWWWWSESSSWS
    20
    SSSWWNENNNNNWWWWSSSS
    30
    EEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
    13
    SWWWWWWWWWNEE0

    样例输出

    The worm successfully made all 18 moves.
    The worm ran into itself on move 9.
    The worm ran off the board on move 21.
    The worm successfully made all 13 moves.

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部