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 ...
随机推荐
- pt-online-schema-change在线修改脚本
pt-online-schema-change在线修改脚本 经过几次在测试环境中使用,发现5.6和5.7可以正常使用.mysql8.0.18版本中,竟然无法使用,感到惊讶.难道mysql8.0.18强 ...
- docker容器共享宿主机环境,从而为镜像体积减负
一.背景介绍 响应公司技术发展路线,开发的服务均需要将打成docker镜像,使用docker进行统一管理.可是随着服务越来越多,镜像也越来越多.每次制作镜像的时候都需要将依赖打进容器,这样一个jre的 ...
- 破解wifi_失败
sudo apt install reaver aircrack-ng //安装需要的软件包ifconfig //获取本地网卡接口sudo airmon-ng start wlp3s0 //无线网卡设 ...
- K8S in Action
1,容器的概念 镜像 镜像仓库 容器 镜像层:Docker镜像由多层构成.好处:网络分发效率,减少镜像的存储空间 1.2 k8s 主节点 ,它承载着 Kubernetes 控制和管理整个集群系统的控制 ...
- 线程优先级队列( Queue)
Python的Queue模块中提供了同步的.线程安全的队列类,包括FIFO(先入先出)队列Queue,LIFO(后入先出)队列LifoQueue,和优先级队列PriorityQueue.这些队列都实现 ...
- luogu 4927 [1007]梦美与线段树 概率与期望 + 线段树
考场上切了不考虑没有逆元的情况(出题人真良心). 把概率都乘到一起后发现求的就是线段树上每个节点保存的权值和的平方的和. 这个的修改和查询都可以通过打标记来实现. 考场代码: #include < ...
- 论文阅读:Flow-level State Transition as a New Switch Primitive for SDN
Name of article:Flow-level State Transition as a New Switch Primitive for SDN Origin of the article: ...
- BZOJ 2731 Luogu P3219 [HNOI2012]三角形覆盖问题 (扫描线)
题目链接: (bzoj)https://www.lydsy.com/JudgeOnline/problem.php?id=2731 (luogu)https://www.luogu.org/probl ...
- Spring Data Jpa (四)注解式查询方法
详细讲解声明式的查询方法 1 @Query详解 使用命名查询为实体声明查询是一种有效的方法,对于少量查询很有效.一般只需要关心@Query里面的value和nativeQuery的值.使用声明式JPQ ...
- [design pattern](7) Singleton
前言 上面的章节中,我们介绍了工厂模式,它是创建型模式的一种.本章我们将会介绍 单例模式 ,它也是创建型模式的一种.单例模式是我们比较常用的一个设计模式,也是最简单的一种设计模式. 单例模式 介绍:确 ...