21317_FlipandShif

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

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

Pro.ID

21317

Title

Flip and Shift

Title链接

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

AC

11

Submit

19

Ratio

57.89%

时间&空间限制

  • Time Limit: 200/100 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    This puzzle consists of a random sequence of m black disks and n white disks on an oval-shaped track, with a turnstile capable of flipping (i.e., reversing) three consecutive disks. In Figure 1, there are 8 black disks and 10 white disks on the track. You may spin the turnstile to flip the three disks in it or shift one position clockwise for each of the disks on the track (Figure 1).

    Figure 1. A flip and a shift

    The goal of this puzzle is to gather the disks of the same color in adjacent positions using flips and shifts. (Figure 2)

    Figure 2. A goal sequence

    You are to write a program which decides whether a given sequence can reach a goal or not. If a goal is reachable, then write a message "YES"; otherwise, write a message "NO".

    输入

    The input consists of T test cases. The number of test cases T is given in the first line of the input. Each of the next T lines gives a test case. A test case consists of an integer, representing the sum of m and n, and a sequence of m+n 0s and 1s, representing an initial sequence. A 0 denotes a white disk and a 1 denotes a black disk. The sum of m and n is at least 10 and does not exceed 30. There is a space between numbers.

    输出

    Description

    This puzzle consists of a random sequence of m black disks and n white disks on an oval-shaped track, with a turnstile capable of flipping (i.e., reversing) three consecutive disks. In Figure 1, there are 8 black disks and 10 white disks on the track. You may spin the turnstile to flip the three disks in it or shift one position clockwise for each of the disks on the track (Figure 1).

    Figure 1. A flip and a shift

    The goal of this puzzle is to gather the disks of the same color in adjacent positions using flips and shifts. (Figure 2)

    Figure 2. A goal sequence

    You are to write a program which decides whether a given sequence can reach a goal or not. If a goal is reachable, then write a message "YES"; otherwise, write a message "NO".

    Input

    The input consists of T test cases. The number of test cases T is given in the first line of the input. Each of the next T lines gives a test case. A test case consists of an integer, representing the sum of m and n, and a sequence of m+n 0s and 1s, representing an initial sequence. A 0 denotes a white disk and a 1 denotes a black disk. The sum of m and n is at least 10 and does not exceed 30. There is a space between numbers.

    Output

    The output should print either "YES" or "NO" for each test case, one per line.

    Sample Input

    2
    18 0 0 1 0 1 1 1 1 0 1 0 0 1 0 0 0 0 1
    14 1 1 0 0 1 1 1 0 0 1 1 0 1 0

    Sample Output

    YES
    NO

    Source

    样例输入

    2
    18 0 0 1 0 1 1 1 1 0 1 0 0 1 0 0 0 0 1
    14 1 1 0 0 1 1 1 0 0 1 1 0 1 0

    样例输出

    YES
    NO

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部