其他分享
首页 > 其他分享> > POJ1063 Flip and Shift(思维)

POJ1063 Flip and Shift(思维)

作者:互联网

链接:https://ac.nowcoder.com/acm/problem/105660
来源:牛客网

题目描述

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).

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

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". img img

输入描述:

The input consists of T test cases. The number of test cases ) (T is given in the first line of the input file. 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.

输出描述:

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

示例1

输入

[复制](javascript:void(0)

标签:POJ1063,位置,奇数,Shift,disks,sequence,Flip,偶数,test
来源: https://www.cnblogs.com/lipoicyclic/p/14729579.html