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. ...
随机推荐
- Java学习05 (第一遍) - JSP与Servlet
JSP 客户端发出Request请求,JSP容器将JSP转译为Servlet的源码,再编译加载到内存执行,结果Response到客户端. Request->JSP->Servlet(jav ...
- C# DataTable To Entities
原地址忘了,修改过了一下. new: public static class DataTableEntityInteroperate { public static List<T> ToE ...
- Zabbix监控系统配置
1.Zabbix是一个基于WEB界面的提供分布式系统监控的企业级的开源解决方案 Zabbix能监视各种网络参数,保证服务器系统的安全稳定的运行,并提供灵活的通知机制以让SA快速定位并解决存在的各种问题 ...
- python字典dict的增、删、改、查操作
## python字典dict的增.删.改.查操作dict = {'age': 18, 'name': 'jin', 'sex': 'male', }#增# dict['heigh'] = 185 # ...
- js基础-单体对象日期对象
Math对象 全局对象 日期对象 var t = new Date() t.toLocaleDateString(); t.getFullYear(); t.getMonth() + 1 t.getD ...
- 税控服务器 TC5002UpdatePackage 安装更新
Linux版税控服务器单税号版本税控应用: TC5002UpdatePackage2008160711.zip 单税号服务器(型号:TCG-01S1) Linux版税控服务器20个 ...
- linux下arm汇编注释符
注意使用 @ 符 # 是整行注释符 @ 是行内注释符 以为 @ 是行内注释符,害我调试了半天.
- java-学习2
第一节 Java语言介绍 1.Java的起源 Oak-->Java 交互式操作智能家居 2.Java的发展 Java1.0 Java1.2 JavaSE :Java平台标准版 ...
- Android Studio 统计行数
开发中常常会想看看自己累积在这个项目中写了多少代码了,以下就是在Android Studio查看统计项目代码总行数的方法. 打开Android Studio,按快捷键Ctrl+Shift+A 输入fi ...
- ArrayList集合类
⦁ 集合概述A:我们学习的是面向对象编程语言,而面向对象编程语言对事物的描述都是通过对象来体现的. 为了方便对多个对象进行操作,我们就必须对这多个对象进行存储,而要想对多个对象进行存储, 就不能是一个 ...