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. ...
随机推荐
- CentsOS6 Tomcat7 报javax.management.InstanceNotFoundException 解决办法
警告: Failed to unregister MBean with name [Catalina:j2eeType=Servlet,name=UploadServlet,WebModule=//l ...
- openfire连接数据库mysql
openFire下载地址http://www.igniterealtime.org/downloads/index.jsp#openfire 如果有UAC保护的话,需要右键以管理员方式启动openfi ...
- 微信小程序--分享报错(thirdScriptError Cannot read property 'from' of undefined;at pages/index/index page onShareAppMessage function TypeError: Cannot read property 'from' of undefined)
分享功能: onShareAppMessage: function (res) { if (res.from === 'button') { // 来自页面内转发按钮 console.log(res. ...
- jenkins commande not found
解决方法: http://www.geekcome.com/content-10-3868-1.html 1.控制台执行 echo $PATH 把输出的这句话复制 2.jenkins->系统管理 ...
- Redis服务器开启远程访问
重启 ps aux|grep redis root 32684 0.0 0.0 48452 6944 ? Ssl 21:27 0:00 ./redis-server *:6379 kill了这个进程 ...
- 2018面向对象程序设计(Java)第11周学习指导及要求
2018面向对象程序设计(Java)第11周学习指导及要求 (2018.11.8-2018.11.11) 学习目标 (1) 掌握Vetor.Stack.Hashtable三个类的用途及常用API: ...
- 2017-2018面向对象程序设计(Java)课程助教工作职责及分工
2017-2018面向对象程序设计(Java)课程助教工作职责及分工 一.研究生助教团队名单 张光辉,王玉环,牟巧玲,徐进 二.工作职责与要求 1) 针对所指导学习小组学生,批改课程实验作业每周一次, ...
- python list 常用
l = [,,,] b = [,,] l.remove() #val del l[] #key new_list = l.extend(b) #[,,,,,,] new_list = l.append ...
- redis 配置参数
redis配置参数说明: 属性 说明 daemonize 如果值是“yes”,则启动服务的时候是后台守护进程形式,如果值是“no”,则相反 pidfile 指定存储Redis进程号的文件路径 port ...
- Centos新增group和user
新增group groupadd hadoop 新增用户 useradd -d /usr/hadoop -g hadoop -m hadoop 设置密码 passwd hadoop