| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 643 人关注过本帖
标题:Flip and Shift
只看楼主 加入收藏
huangyong0701
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-8-23
收藏
 问题点数:0 回复次数:1 
Flip and Shift
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).



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

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

Taejon 2001

[Submit]   [Go Back]   [Status]   [Discuss]

Home Page   Go Back  To top

此题用C怎么编呢
搜索更多相关主题的帖子: Flip Shift 
2008-08-23 10:22
leeco
Rank: 4
等 级:贵宾
威 望:10
帖 子:1029
专家分:177
注 册:2007-5-10
收藏
得分:0 
这是一个结论题,没有编程难度,只要你看出规律
2008-08-23 18:02
快速回复:Flip and Shift
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015898 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved