Minimum number of steps 805D
http://codeforces.com/contest/805/problem/D
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 modulo109 + 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 from1 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".
题意:将字符串中ab 替换成 bba 进行多少次操作字符串中没有 ab
分析:将字符ab 替换成 bba 可以看成 a 向右移动一位, ab 中的 b 后增加一个 b
每次将a 字符移动到所有b字符 的右端, 下一个a右边的b就多了一倍, 所以每遇到一个a 加上右边的b,然后更新右边的b为2*b
#include <bits/stdc++.h>
using namespace std;
#define ll long long const ll mod = 1e9 + ;
// "ab" ?→? "bba".
// "aab" ?→? "abba" ?→? "bbaba"?→? "bbbbaa". int main(){
string str;
while(cin >> str){
//cout << str << endl;
ll b = ;
ll ans = ;
for(ll i = str.length() - ; i >= ; i--){
// cout << "b " << b<< endl;
if(str[i] == 'b')
b++;
//cout << "b " << b<< endl;
if(str[i] == 'a'){
ans += b%mod;
//cout << ans << endl;
ans %= mod;
b *= ;
b %= mod;
}
}
cout << ans% mod << endl;
}
}
Minimum number of steps 805D的更多相关文章
- Codeforces 805D - Minimum number of steps
805D - Minimum number of steps 思路:简单模拟,a每穿过后面一个b,b的个数+1,当这个a穿到最后,相当于把它后面的b的个数翻倍.每个a到达最后的步数相当于这个a与它后面 ...
- Minimum number of steps CodeForces - 805D(签到题)
D. Minimum number of steps time limit per test 1 second memory limit per test 256 megabytes input st ...
- 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 ...
- 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 Round #411 (Div. 1) B. Minimum number of steps
最后肯定是bbbb...aaaa...这样. 你每进行一系列替换操作,相当于把一个a移动到右侧. 会增加一些b的数量……然后你统计一下就行.式子很简单. 喵喵喵,我分段统计的,用了等比数列……感觉智障 ...
- 【贪心】codeforces D. Minimum number of steps
http://codeforces.com/contest/805/problem/D [思路] 要使最后的字符串不出现ab字样,贪心的从后面开始更换ab为bba,并且字符串以"abbbb. ...
随机推荐
- MySQL C#连接ySQL保存当前时间,时分秒都是0,只有日期
原因:MySQL的字段格式是:date 解决: 1.把 字段格式 改为 datetime 2.映射 的字段类型 也要改为 datetime
- 学习JS的心路历程-参数的传递(下)
今天我们要来探讨JS到底是透过何种参数传递方式呢? 废话不多说,上示例!! 我们先声明原始型别和物件型别来看看两者是否会有不一样的差异: var myStr = 'Hola': var myObj = ...
- tensflow分布式
https://blog.csdn.net/CodeMaster_/article/details/76223835 代码解析好文: https://wenku.baidu.com/view/94b2 ...
- ubuntu14配置opencv3.4.1(转)
网站:https://blog.csdn.net/a1429331875/article/details/31539129 写此博客的目的是为了方便大家的学习,我是搞了半天,通过上网查找资料才成功的. ...
- Python+Appium自动化环境搭建
appium工作原理 appium 在android端工作流 client端也就是我们 test script是我们的webdriver测试脚本. 中间是起的Appium的服务,Appium在服务端起 ...
- 04_web基础(一)之tomcat介绍
01.web引入 在这之前我们已经能够在数据库进行CRUD,在dao处进行CRUD,在service处进行CRUD,对用户来说必须在浏览器上进行CRUD,要完成这个就必须具备web知识. 而web运行 ...
- ATM--代码
//信1705-2 张小军 20173662 import java.io.*; import java.util.ArrayList; import java.util.Scanner;public ...
- asp.net导出excle
思路:实际上是读取页面上某个控件下的内容再导出 protected void btnExcel_Click(object sender, EventArgs e) { string bgType = ...
- python 文件操作: 文件操作的函数, 模式及常用操作.
1.文件操作的函数: open("文件名(路径)", mode = '模式', encoding = "字符集") 2.模式: r , w , a , r+ , ...
- k8s volume 基本类型分类
volume 类型 静态volume emptyDir 临时空目录, 用途,pod内多用户同享一个目录.与POD的生命周期一至,POD创建时创建,删除时删除. Hostpath 宿主机1:1映射,用途 ...