题意:

给定一串字符串,将所有“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. spring源代码下载并导入eclipse技巧

    环境:mac 安装brew /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install ...

  2. _bzoj1002 [FJOI2007]轮状病毒【瞎搞】

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1002 这种题真是有毒,很多叼一点的都用matrix tree定理推出了递推公式,也有一些用好 ...

  3. 51nod 1154 回文串划分

    1154 回文串划分 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题  收藏  关注 有一个字符串S,求S最少可以被划分为多少个回文串. 例如:abbaabaa,有 ...

  4. Tree POJ - 174

    点分模板题 都快改的跟题解一模一样了2333333 #include<cstdio> #include<cstring> #include<algorithm> u ...

  5. DP + 概率 + 贪心 UVA 1456 Cellular Network

    题目传送门 题意:(摘自LRJ<训练指南>) 手机在蜂窝网络中的定位是一个基本问题.假设蜂窝网络已经得知手机处于c1, c2,…,cn这些区域中的一个,最简单的方法是同时在这些区域中寻找手 ...

  6. DP(两次) UVA 10163 Storage Keepers

    题目传送门 /* 题意:(我懒得写,照搬网上的)有n个仓库,m个人看管.一个仓库只能由一个人来看管,一个人可以看管多个仓库. 每个人有一个能力值pi,如果他看管k个仓库,那么所看管的每个仓库的安全值为 ...

  7. 可以装一把——c#中手动添加控件

    TextBox txt = new TextBox(); //文本框控件 //如果想在移动控件位置 point(x,y) txt.Location = new Point(50,50); this.C ...

  8. (五)Mybatis总结之一对多、一对一

    一对多 业务场景:张三既是java开发师又是大学老师又是LOL代练,张三拥有多个角色. 1.创建实体类UserInfo和RoleInfo package com.qf.mybatisdemo.pojo ...

  9. InChatter系统之客户端消息处理中心

    一.模块结构 首先来看下客户端消息处理中心模块的简单结构: ChatCallback:服务器端我们定义的回调接口IChatCallback的客户端实现 ChatMsgCenter:服务端的消息处理中心 ...

  10. css定位position属性深究

    1.static:对象遵循常规流.此时4个定位偏移属性不会被应用. 2.relative:对象遵循常规流,并且参照自身在常规流中的位置通过top,right,bottom,left这4个定位偏移属性进 ...