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. ...
随机推荐
- <assert.h>库学习
assert的初步认识 assert宏指令是用来诊断程序是否有误的,函数原型如下 void assert(int expression) 那为什么我们要使用assert而不用printf呢?因为ass ...
- ubuntu18换国内源
编辑/etc/apt/sources.list文件, 在文件最前面添加以下条目(操作前请做好相应备份): ##中科大源 deb https://mirrors.ustc.edu.cn/ubuntu/ ...
- css flex 兼容ios android--商品展示 添加购物车
https://blog.csdn.net/u010035608/article/details/52711248 <!DOCTYPE html> <html> <hea ...
- 【C++】子类访问父类typedef的问题
class A { public: typedef int* pointer; }; class B :public A { public: pointer b; }; 这段代码运行没有问题,子类继承 ...
- vmware 共享文件夹
参考 https://jingyan.baidu.com/article/7f766daf7866be4101e1d0ed.html 只是设置共享文件夹选项还不行,需要从安装vmware的安装路径中找 ...
- springboot jpa sql查询与传值
public interface ARepository extends PagingAndSortingRepository<A, APK>, JpaSpecificationExecu ...
- dedecms 后台修改系统设置,但是config.cache.inc.php文件不能写入
fopen居然返回false,既不是目录或文件权限相关问题,也不是文件路径问题(相对路径.绝对路径)等,更不是打开文件的模式问题(r,w,a等).网上搜了一会,说到返回false的原因无非都是上面三种 ...
- 203. Remove Linked List Elements (List)
Remove all elements from a linked list of integers that have value val. ExampleGiven: 1 --> 2 --& ...
- ACM-ICPC 2018 南京赛区网络预赛 G. Lpl and Energy-saving Lamps(二分+线段树区间最小)
During tea-drinking, princess, amongst other things, asked why has such a good-natured and cute Drag ...
- Inno Setup安装程序单例运行
1.源起: KV项目下载底层升级包,老是报出升级文件占用问题,反复分析,不得其所. 今天突然发现同时启动多个升级程序实例,分析认为安装包同时被调用多次,引发实例访问文件冲突,导致此问题. 安装程序由I ...