POJ 1063 - Flip and Shift
Description

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
Output
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
当总的个数n为odd时,任何一个球都能到达圆圈中的每一个位置,所以就是YES。
当总的个数n为even时,那么如果这个球的位置在odd位置上,那么它能到任意一个odd位置,若在even位置上,则能到任意一个even位置。
那么不妨把黑球全部移到一起,不去管白球,那么如果偶数位置的黑球更多一些,中间就夹着少一个的奇数的空位,把剩下的那些奇数个黑球放进去,如果 even - odd = 0 or 1 ,那么这个时候是可以把空位放满的,否则就放不满,即NO;类似的如果odd位置的黑球更多一点,就判断odd - even = 0 or 1是否为真即可。
#include<stdio.h>
#include<stdlib.h>
int main()
{
int even,odd;
int i,n,disk[],T;scanf("%d",&T);
while(T){
scanf("%d",&n);
for(i=;i<n;i++) scanf("%d",&disk[i]);
if( n% == ) printf("YES\n"); //n为odd,必然YES
else{
even=,odd=; //初始化even位和odd位的黑球数
for(i=;i<n;i++){
if( disk[i]== && i%== ) odd++; //odd位黑球计数
if( disk[i]== && i%== ) even++; //even位黑球计数
}
if(abs(odd-even)>) printf("NO\n"); //判断"|odd - even| = 0 or 1"是否成立
else printf("YES\n");
}
T--;
}
}
POJ 1063 - Flip and Shift的更多相关文章
- POJ 1063 Flip and Shift 最详细的解题报告
题目来源:Flip and Shift 题目大意:一个椭圆形的环形容器中有黑色和白色两种盘子,问你是否可以将黑色的盘子连续的放在一起.你可以有以下两种操作: 1.顺时针旋转所有的盘子 2.顺时针旋转3 ...
- POJ1063 Flip and Shift
题目来源:http://poj.org/problem?id=1063 题目大意: 有一种游戏如图所示.一个填满黑白球的转盘,它可以有两种操作,一种是将大转盘顺时针旋转,所有球的位置顺时针挪一位,另一 ...
- 枚举 POJ 1753 Flip Game
题目地址:http://poj.org/problem?id=1753 /* 这题几乎和POJ 2965一样,DFS函数都不用修改 只要修改一下change规则... 注意:是否初始已经ok了要先判断 ...
- zoj 1028 Flip and Shift(数学)
Flip and Shift Time Limit: 2 Seconds Memory Limit: 65536 KB This puzzle consists of a random se ...
- POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37427 Accepted: 16288 Descr ...
- OpenJudge/Poj 1753 Flip Game
1.链接地址: http://bailian.openjudge.cn/practice/1753/ http://poj.org/problem?id=1753 2.题目: 总时间限制: 1000m ...
- POJ 1753 Flip Game(高斯消元+状压枚举)
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 45691 Accepted: 19590 Descr ...
- POJ 1753 Flip Game DFS枚举
看题传送门:http://poj.org/problem?id=1753 DFS枚举的应用. 基本上是参考大神的.... 学习学习.. #include<cstdio> #include& ...
- POJ 1753 Flip Game(状态压缩+BFS)
题目网址:http://poj.org/problem?id=1753 题目: Flip Game Description Flip game is played on a rectangular 4 ...
随机推荐
- php static 变量的例子
class test { public static function a(){} public function b(){} } $obj = new test; 调用 代码 test::a(); ...
- Vue(八):监听属性watch
Vue.js 可以通过 watch 来响应数据的变化. 以下实例模拟购物车里商品数量增加,对应价格也增加 <!--模拟购物车商品数量增加,价格也随之增加--> <div id = & ...
- shell函数【参数传递及输入输出】&内置函数
Linux——shell脚本基础3:shell函数[参数传递及输入输出]&内置函数 函数定义 1 退出状态 1 参数传递 2 标准IO 2 脚本调试 2 AND&OR 3 内置命令补充 ...
- linux source code search
https://elixir.bootlin.com/linux/latest/source/fs/eventpoll.c#L1120
- 每日英语:Doc, Do I Need A Juice Cleanse?
Some drink only vegetable juice. Others soak in Epsom salts. It's all in the pursuit of ridding the ...
- 【驱动】Linux初级驱动系列框架
[系统环境搭建] 1.uboot的命令 set serverip .xx set ipaddr .xxx set bootcmd tftp zImage\;bootm //开发模式 set bootc ...
- Spring-boot初始化创建(一)
Spring Boot 是什么 Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人 ...
- 能ping通外网的域名,浏览器不能上网的解决办法
1,依次尝试了关闭防火墙,关闭杀毒软件,手动设置DNS都没有用. 2,最后通过这个cmd命令搞定,特此记录一下,重置初始化网络环境. netsh winsock reset 补充,上面的命令,重启电脑 ...
- Android图片处理(Matrix,ColorMatrix)
转发说明:原文链接http://www.cnblogs.com/leon19870907/articles/1978065.html 在编程中有时候需要对图片做特殊的处理,比如将图片做出黑白的,或者老 ...
- Pytest运行测试用例的多种方式和调试
测试用例上方使用多个fixtures叠加时,是从下往上进行fixtures调用的.如果是 @pytest.mark.usefixtures('action','a','action2')这种形式,是从 ...