Minimum number of steps CodeForces - 805D(签到题)
1 second
256 megabytes
standard input
standard output
We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109 + 7.
The string "ab" appears as a substring if there is a letter 'b' right after the letter 'a' somewhere in the string.
The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106.
Print the minimum number of steps modulo 109 + 7.
ab
1
aab
3
The first example: "ab" → "bba".
The second example: "aab" → "abba" → "bbaba" → "bbbbaa".
从后向前 遍历
每个a都会把它后边的b变到后边 且乘二
而每个a后边b的个数 即为当前a变化的次数
#include <bits/stdc++.h>
#define mem(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long LL;
const int maxn = , INF = 0x7fffffff;
const int MOD = 1e9 + ;
int n;
string str; int main()
{ cin >> str;
int len = str.size();
int ans = , cnt = ;
for(int i = len - ; i >= ; i--)
{
if(str[i] == 'b')
cnt++;
else
{
ans = (ans + cnt) % MOD;
cnt = (cnt * ) % MOD;
} }
cout << ans << endl; return ;
}
1 second
256 megabytes
standard input
standard output
We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109 + 7.
The string "ab" appears as a substring if there is a letter 'b' right after the letter 'a' somewhere in the string.
The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106.
Print the minimum number of steps modulo 109 + 7.
ab
1
aab
3
The first example: "ab" → "bba".
The second example: "aab" → "abba" → "bbaba" → "bbbbaa".
Minimum number of steps CodeForces - 805D(签到题)的更多相关文章
- Codeforces 805D - Minimum number of steps
805D - Minimum number of steps 思路:简单模拟,a每穿过后面一个b,b的个数+1,当这个a穿到最后,相当于把它后面的b的个数翻倍.每个a到达最后的步数相当于这个a与它后面 ...
- Codeforces Round #411 div 2 D. Minimum number of steps
D. Minimum number of steps time limit per test 1 second memory limit per test 256 megabytes input st ...
- Minimum number of steps 805D
http://codeforces.com/contest/805/problem/D D. Minimum number of steps time limit per test 1 second ...
- codeforce 804B Minimum number of steps
cf劲啊 原题: We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each ...
- Codeforces805D. Minimum number of steps 2017-05-05 08:46 240人阅读 评论(0) 收藏
D. Minimum number of steps time limit per test 1 second memory limit per test 256 megabytes input st ...
- 【codeforces 805D】Minimum number of steps
[题目链接]:http://codeforces.com/contest/805/problem/D [题意] 给你一个字符串; 里面只包括a和b; 让你把里面的"ab"子串全都去 ...
- Codeforces 805D/804B - Minimum number of steps
传送门:http://codeforces.com/contest/805/problem/D 对于一个由‘a’.‘b’组成的字符串,有如下操作:将字符串中的一个子串“ab”替换成“bba”.当字符串 ...
- codeforces 805 D. Minimum number of steps(数学)
题目链接:http://codeforces.com/contest/805/problem/D 题意:只有一个操作就是将ab变成bba直到不能变为止,问最少边几次. 题解:这题可以多列几组来找规律, ...
- 【贪心】codeforces D. Minimum number of steps
http://codeforces.com/contest/805/problem/D [思路] 要使最后的字符串不出现ab字样,贪心的从后面开始更换ab为bba,并且字符串以"abbbb. ...
随机推荐
- RabbitMQ教程(二) ——linux下安装rabbitmq
安装过程参考官网: Installing on RPM-based Linux (RHEL, CentOS, Fedora, openSUSE) 首先需要安装erlang,参考:http://fedo ...
- Method not found: !!0[] System.Array.Empty()错误
最近由于公司项目需要将之前支持的TLS1.0改成更安全的TLS1.2,而公司现有项目都是老系统,有的是.NET FrameWork 4.0,有的是.NET FrameWork3.5,但是TLS1.2默 ...
- 关于getHibernateTemplate().get()方法
返回的对象值唯一,方法带有两个参数 第一个是意图查询实体的Class 如User.Class ;第二个参数是该实体在数据库中对应的主键值,而且参数的类型要和映射文件相对应. 如 Role role ...
- B. School Marks(典型贪心)
链接 [https://codeforces.com/contest/540/problem/B] 题意 某个人有n门成绩,k门已知,剩下的他可以个瞎改,但有个要求,最后分数和不超过x,且每门成绩不超 ...
- mysql有多大内存?能存多少数据?
Mysql: MySQL 3.22 限制的表大小为4GB. MyISAM 存储引擎: 最大表尺寸增加到了65536TB(2567 – 1字节).由于允许的表尺寸更大,MySQL数据库的最大有效表尺寸通 ...
- 【学习总结】之 3Blue1Brown系列
刷知乎看到的,各种力荐. YouTube: https://www.youtube.com/channel/UCYO_jab_esuFRV4b17AJtAw/featured B站: https:// ...
- Python3练习题 026:求100以内的素数
p = [i for i in range(2,100)] #建立2-99的列表 for i in range(3,100): #1和2都不用判断,从3开始 for j in range(2, ...
- css引入的两种方法link和@import的区别和用法
link和@import都是HTML中引入CSS的语法单词. 两者的基本语法 link语法结构 <link href="外部CSS文件的URL路径" rel="st ...
- Oracle Flashback 详解
Oracle flashback 是一种方便快捷的数据库恢复技术,它不使用备份文件,通过闪回日志可以使数据库恢复到过去的某个状态,当用户发生逻辑错误时(误删表数据.表.表空间等)需要快速恢复数据库,可 ...
- java中级——集合框架【4】-Collections
Collections 首先我们要知道Collections是一个类,容器的工具类,就如同Arrays是数组的工具类 反转 reverse 使List中的数据发生发转 package cn.jse.c ...