题意:

给定一串字符串,将所有“ab”的子串替换为“bba”,询问多少次操作后没有子串“ab”。

分析:

观察可得,将“ab”替换为“bba”有两种结果。

①a移到了b的后面

②增加了一个b

而且最终的结果一定是前面全是b,后面全是a。

所以可以猜想从后往前数,设置一个B_cnt, 每当碰到一个b, 就b_cnt++, 碰到A, 就先加上一个b_cnt(因为每替换一次会将a移动后一格,所以要替换b_cnt次),再将b_cnt*2(多出b_cnt个b)。

 #include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <string>
#include <iostream>
#include <set>
#include <sstream>
#include <algorithm>
using namespace std;
const int MOD = 1e9 +;
const int maxn = 1e6+;
char str[maxn];
int main()
{
scanf("%s", str);
int len = strlen(str);
int cnt = ;
int res = ;
for(int i = len - ; i >= ; i--)
{
if(str[i] == 'b')
{
cnt++;
}
else
{
res += cnt;
res %= MOD;
cnt *= ;
cnt %= MOD;
}
}
printf("%d\n", res);
}

Codeforces 805 D Minimum number of steps的更多相关文章

  1. codeforces 805 D. Minimum number of steps(数学)

    题目链接:http://codeforces.com/contest/805/problem/D 题意:只有一个操作就是将ab变成bba直到不能变为止,问最少边几次. 题解:这题可以多列几组来找规律, ...

  2. 【codeforces 805D】Minimum number of steps

    [题目链接]:http://codeforces.com/contest/805/problem/D [题意] 给你一个字符串; 里面只包括a和b; 让你把里面的"ab"子串全都去 ...

  3. Codeforces 805D/804B - Minimum number of steps

    传送门:http://codeforces.com/contest/805/problem/D 对于一个由‘a’.‘b’组成的字符串,有如下操作:将字符串中的一个子串“ab”替换成“bba”.当字符串 ...

  4. 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 ...

  5. 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 ...

  6. Codeforces 805D - Minimum number of steps

    805D - Minimum number of steps 思路:简单模拟,a每穿过后面一个b,b的个数+1,当这个a穿到最后,相当于把它后面的b的个数翻倍.每个a到达最后的步数相当于这个a与它后面 ...

  7. Minimum number of steps 805D

    http://codeforces.com/contest/805/problem/D D. Minimum number of steps time limit per test 1 second ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. Lodash 方法库 原生实现 待完结。。。

    'use strict' let _ = { // 将数组(array)拆分成多个 size 长度的区块,并将这些区块组成一个新数组. 如果array 无法被分割成全部等长的区块,那么最后剩余的元素将 ...

  2. html 解决空格显示问题

    前端开发者都知道,在html中手动输入多个空格或者是回车,在页面解析的时候都被解析成一个空白显示,但有时候的需求要求显示多个空格,这个问题怎么解决呢?根绝我个人的经验,目前找到了以下集中解决办法: 1 ...

  3. ————————C语言中快速排序方法——————————————

    在对浮点型排序是一定要用三木运算符(三目运算符内容下去自己看),因为如果也是用整形那样的减法的时候如果是两个十分相近的数字 可能返回一个小数(自己一会去试试),冉冉他cmp返回值是int(试试别的)因 ...

  4. MVC、MVP和MVVM的更简单易懂的理解

    本篇转自网络: 一.MVC MVC模式的意思是,软件可以分成三个部分. 视图(View):用户界面. 控制器(Controller):业务逻辑 模型(Model):数据保存 各部分之间的通信方式如下. ...

  5. UVA 11149 Power of Matrix 构造矩阵

    题目大意:意思就是让求A(A是矩阵)+A2+A3+A4+A5+A6+······+AK,其中矩阵范围n<=40,k<=1000000. 解题思路:由于k的取值范围很大,所以很自然地想到了二 ...

  6. _bzoj3224 Tyvj 1728 普通平衡树【Splay】

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=3224 保存splay模版 一刻不停写了一个小时多一点,幸好一遍过了!(其实带着freopen ...

  7. magento 用程序生成优惠劵码

    参考自http://fragmentedthought.com/fragments/programatically-creating-sales-rule-coupon-code 上面的代码只能生成C ...

  8. Retinex系列之McCann99 Retinex 分类: 图像处理 Matlab 2014-12-03 11:27 585人阅读 评论(0) 收藏

    一.McCann99 Retinex McCann99利用金字塔模型建立对图像的多分辨率描述,自顶向下逐层迭代,提高增强效率.对输入图像的长宽有 严格的限制,要求可表示成 ,且 ,. 上述限制来源于金 ...

  9. dalvik.system.VMRuntime 隐藏api的迷惑

    [Android UI界面]关于dalvik.system.VMRuntime 的 使用迷惑 我也遇到了相同问题.不知楼主现在解决了没有? 回答1: [Android UI界面]关于dalvik.sy ...

  10. Hibernate配置(外部配置文件方式)

    配置Hibernate有2种方式,本文讲的是通过外部配置文件配置的方式 Hibernate核心配置文件 <?xml version='1.0' encoding='UTF-8'?> < ...