22395_RotatingRings

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

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

Pro.ID

22395

Title

Rotating Rings

Title链接

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

AC

0

Submit

0

Ratio

-

时间&空间限制

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

    Any square grid can be viewed as one or more rings, one inside the other. For example, as shown in figure (a), a 5×5 grid is made of three rings, numbered 1, 2 and 3 (from outside to inside.) A square grid of size N is said to be sorted, if it includes the values from 1 to N2 in a row-major order, as shown in figure (b) for N = 4. We would like to determine if a given square grid can be sorted by only rotating its rings. For example, the grid in figure (c) can be sorted by rotating the first ring two places counter-clockwise, and rotating the second ring one place in the clockwise direction.

    输入

    Your program will be tested on one or more test cases. The first input line of a test case is an integer N which is the size of the grid. N input lines will follow, each line made of N integer values specifying the values in the grid in a row-major order. Note than 0 < N ≤ 1, 000 and grid values are natural numbers less than or equal to 1,000,000.

    The end of the test cases is identified with a dummy test case with N = 0.

    输出

    Description

    Any square grid can be viewed as one or more rings, one inside the other. For example, as shown in figure (a), a 5×5 grid is made of three rings, numbered 1, 2 and 3 (from outside to inside.) A square grid of size N is said to be sorted, if it includes the values from 1 to N2 in a row-major order, as shown in figure (b) for N = 4. We would like to determine if a given square grid can be sorted by only rotating its rings. For example, the grid in figure (c) can be sorted by rotating the first ring two places counter-clockwise, and rotating the second ring one place in the clockwise direction.

    Input

    Your program will be tested on one or more test cases. The first input line of a test case is an integer N which is the size of the grid. N input lines will follow, each line made of N integer values specifying the values in the grid in a row-major order. Note than 0 < N ≤ 1, 000 and grid values are natural numbers less than or equal to 1,000,000.

    The end of the test cases is identified with a dummy test case with N = 0.

    Output

    For each test case, output the result on a single line using the following format:

    k. result

    Where k is the test case number (starting at 1,)  is a single space, and result is "YES" or "NO" (without the double quotes.)

    Sample Input

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

    Sample Output

    1. YES
    2. NO

    Source

    样例输入

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

    样例输出

    1. YES
    2. NO

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部