Sequential game

Problem Description

Sequential detector is a very important device in Hardware experiments. But is very difficult for many students such as HeroWei. In nearest days, his teacher Miss Fang let him simulate sequence detector. But there many sequence here ,and Miss Fang add the difficulty that when she give HeroWei a sequence and a string ,you must tell her how many string here in this sequence. But now Miss Fang simplified the problem for HeroWei, she just give Herowei a sequence and let HeroWei play a game with it.
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

Each line contains a composed by a string of 0s and 1s.the
input is ended by EOF.

Output

For each given sequence you just play with this string as
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的更多相关文章

  1. Creating a SharePoint Sequential Workflow

    https://msdn.microsoft.com/en-us/library/office/hh824675(v=office.14).aspx Creating a SharePoint Seq ...

  2. Sequential List

    Sequential ListSequential list storage structure:#define LIST_INIT_SIZE 20 #define LIST_INCREASE 10t ...

  3. Support Vector Machine (2) : Sequential Minimal Optimization

    目录 Support Vector Machine (1) : 简单SVM原理 Support Vector Machine (2) : Sequential Minimal Optimization ...

  4. completed solution matches microsoft sequential workflow tutorial

    microsoft sequential workflow tutorial website:http://msdn.microsoft.com/en-us/library/ms734794(v=vs ...

  5. Time Series data 与 sequential data 的区别

    It is important to note the distinction between time series and sequential data. In both cases, the ...

  6. Java中的查找算法之顺序查找(Sequential Search)

    Java中的查找算法之顺序查找(Sequential Search) 神话丿小王子的博客主页 a) 原理:顺序查找就是按顺序从头到尾依次往下查找,找到数据,则提前结束查找,找不到便一直查找下去,直到数 ...

  7. Loadrunner中参数化实战(1)-Sequential+Each iteration

    参数化数据30条: 脚本如下,演示登录,投资,退出操作是,打印手机号: 首先验证Vugen中迭代: Sequential+Each iteration 设置迭代4次Action 结果如下:

  8. Sequential Read Ahead For SQL Server

    Balancing CPU and I/O throughput is essential to achieve good overall performance and to maximize ha ...

  9. control file sequential read 等待事件

    可能的原因 control file sequential read Reading from the control file. This happens in many cases. For ex ...

  10. sequential minimal optimization,SMO for SVM, (MATLAB code)

    function model = SMOforSVM(X, y, C ) %sequential minimal optimization,SMO tol = 0.001; maxIters = 30 ...

随机推荐

  1. angular-seed — AngularJS种子项目

    AngularJS Seed 是典型 AngularJS web 应用的应用骨架,可以快速启动你的 AngularJS webapp 项目和这些项目的开发环境. AngularJS Seed 包括一个 ...

  2. 2018山东省赛 H Dominoes ( 搜索 )

    题目链接 题意 : 给出一个 n * m 的矩阵,用规格 1 * 2 的多米诺去填充,题目数据保证最后只有一个格子是空白的(即没有被多米诺骨牌覆盖),问你现在通过移动多米诺能够产生多少种不同的状态(空 ...

  3. csp-s2019 AFO记

    DAY 0 上午出发前大家都很颓废的样子. 我因为还没有实现刷完NOIP专题的所有题的目标而去憨比的学DDP. 最后还是不会,保卫王国是写不成了…… 该走了,学校领导来开了个欢送会,祝福我们从里WA到 ...

  4. codevs2833 奇怪的梦境 x

    2833 奇怪的梦境  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold   题目描述 Description Aiden陷入了一个奇怪的梦境:他被困在一个小房子中 ...

  5. Android学习笔记之数据的Sdcard存储方法及操作sdcard的工具类

    FileService.java也就是操作sdcard的工具类: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 ...

  6. D. Restore Permutation

    D. Restore Permutation 就是给一个n个数的全排,然后bi记录比ai小且在排在ai前面的数的和,求ai 树状数组维护,二分 #include<bits/stdc++.h> ...

  7. 5.并发编程-synchronized 细节说明

    并发编程-synchronized 细节说明 1. synchronized-锁重入 & 异常释放锁 说明 * 关键字synchronized 拥有锁重入的功能,也就是在使用synchroni ...

  8. Failed to read artifact descriptor for xxx:jar

    在MyEclipse中执行Maven的install命令时,报“Failed to read artifact descriptor for xxx:jar ”的错误.这可能是在下载过程中文件出现错误 ...

  9. jQuery easyui datagrid 的数据加载

        其实easyuidatagrid加载数据只有两种方式:一种是ajax加载目标url返回的json数据:另一种是加载js对象,也就是使用loadDate方法,这种方法用于加载本地js数据(非ur ...

  10. lnmp源码搭建

      Nginx工作原理 这里需要结合Apache的工作,对PHP文件处理过程的区别 1:Nginx是通过php-fpm这个服务来处理php文件        2:Apache是通过libphp5.so ...