Sequential game
Sequential game
Problem Description
When comes a character , it
must compare with the rightmost one of sequence, if it's the same with the
coming characters ,the coming one just join the string. Most the right side.
Otherwise all the characters in the sequence must change its value, 0 to 1 and 1
to 0,then the coming one add to its right side. Here is an example, if there is
a sequence '110' when comes a character 0,the sequence become '1100' at last, if
comes a character 1,the sequence become '0011' at last.
It's very difficult
for HeroWei to play the game. Can you help him?
Input
input is ended by EOF.
Output
descripted above.Output a line contains two integers ,which are the number of 0s
and 1s in the sequence after the game.
Sample Input
0
110
1111
1010
Sample Output
1 0
3 0
0 4
4 0 [Tips]
For example ,1010: 1->00->111->0000
描述:
题目大意,有一个01的字符流。当 第 i 个字符和第 i-1 个字符不同时,就把前 i-1个字符,每一个字符都改变一下,如果是0就变为1,如果是1就变为0. 当第 i 个字符和第 i-1个字符一样的时候,就什么事都不发生。对于110, 则是
1->11->000. 然后问你,有多少个0, 多少个1. 这问题就有点简单了啊,很容易可以发现,其实只有两种可能,要么全 0, 要么全 1。我们只要记录 这个字符流中字符 1 的 个数。和字符 0 的个数,然后记录最后一个字符就可以了。
如果这个字符流中只有一种字符,那么结果显而易见的。如果都有,那么就全部变成最后一次出现的那个字符,不信的话,自己随手写一个字符流,去推一推,我就是这么发现的规律。
#include<bits/stdc++.h>
using namespace std;
const int N = ;
int main() {
char str[N];
while (cin >> str) {
int len_str = strlen(str);
int sum_1 = , sum_0 = ;
for (int i = ; i < len_str; i++) {
if (str[i] == '') sum_1++;
if (str[i] == '') sum_0++;
if (sum_1 != && sum_0 != ) break;
}
if (sum_1 != && sum_0 != ) {
if (str[len_str - ] == '') {
printf("%d %d\n", , len_str);
} else {
printf("%d %d\n", len_str, );
}
} else {
if (sum_1 == ) printf("%d %d\n", len_str, );
else printf("%d %d\n", , len_str);
}
}
return ;
}
Sequential game的更多相关文章
- Creating a SharePoint Sequential Workflow
https://msdn.microsoft.com/en-us/library/office/hh824675(v=office.14).aspx Creating a SharePoint Seq ...
- Sequential List
Sequential ListSequential list storage structure:#define LIST_INIT_SIZE 20 #define LIST_INCREASE 10t ...
- Support Vector Machine (2) : Sequential Minimal Optimization
目录 Support Vector Machine (1) : 简单SVM原理 Support Vector Machine (2) : Sequential Minimal Optimization ...
- completed solution matches microsoft sequential workflow tutorial
microsoft sequential workflow tutorial website:http://msdn.microsoft.com/en-us/library/ms734794(v=vs ...
- Time Series data 与 sequential data 的区别
It is important to note the distinction between time series and sequential data. In both cases, the ...
- Java中的查找算法之顺序查找(Sequential Search)
Java中的查找算法之顺序查找(Sequential Search) 神话丿小王子的博客主页 a) 原理:顺序查找就是按顺序从头到尾依次往下查找,找到数据,则提前结束查找,找不到便一直查找下去,直到数 ...
- Loadrunner中参数化实战(1)-Sequential+Each iteration
参数化数据30条: 脚本如下,演示登录,投资,退出操作是,打印手机号: 首先验证Vugen中迭代: Sequential+Each iteration 设置迭代4次Action 结果如下:
- Sequential Read Ahead For SQL Server
Balancing CPU and I/O throughput is essential to achieve good overall performance and to maximize ha ...
- control file sequential read 等待事件
可能的原因 control file sequential read Reading from the control file. This happens in many cases. For ex ...
- sequential minimal optimization,SMO for SVM, (MATLAB code)
function model = SMOforSVM(X, y, C ) %sequential minimal optimization,SMO tol = 0.001; maxIters = 30 ...
随机推荐
- vue 路由拦截器和请求拦截器
路由拦截器 已路由为导向 router.beforeEach((to,from,next)=>{ if(to.path=='/login' || localStorage.getItem('to ...
- MySQL——复制(Replication)
1.复制概述 1.1.复制解决的问题数据复制技术有以下一些特点:(1) 数据分布(2) 负载平衡(load balancing)(3) 备份(4) 高可用性(high avai ...
- 各种注意事项(还有c++的一些操作)
转c++时间: 2017年8月9号 1.记得打头文件 2.=与==的区别(赋值|比较) 3.各种运算符的比较级(与Pascal不同),主要是==与位运算 *4.在OJ上scanf和printf时间优于 ...
- LeetCode - 环形链表检测
方法一:哈希表 # Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # se ...
- vscode匹配括号插件
给大家推荐一个vscode匹配括号的插件: Bracket Pair Colorizer.超级好用哦
- ROM和RAM的内存详细说明
1.首先是ROM 的读取是需要提前两个地址的读取,所以要想读取0地址的数据,你需要给地址是2 2.关于宽度,深度的计算 假设我们要存取如下取模的数据,该模的设置口语描述为:这是显示的2个字节,其中一个 ...
- 【javascript】生成二维码
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="UTF-8"> 5 < ...
- 网页结构树DOM
引入 window对象 所有浏览器都支持 window 对象.它表示浏览器窗口. *如果文档包含框架(frame 或 iframe 标签),浏览器会为 HTML 文档创建一个 window 对象,并为 ...
- 金蝶K3 WISE 13.1版本服务器虚拟机环境部署
闲来无事,整个13.1版本的金蝶玩玩. 系统环境:WIN2008 R2,x64位 数据库:MSSQL 2008 R2,X64位 记录下操作步骤: 1.准备安装软件,见图: 2.安装资源包,.net3. ...
- Proxy-代理器(预计vue3.0实现双向绑定的方式)
todo 常见的基于数据劫持的双向绑定有两种实现,一个是目前Vue在用的Object.defineProperty,另一个是ES2015中新增的Proxy,而Vue的作者宣称将在Vue3.0版本后加入 ...