【题目链接】:http://codeforces.com/contest/805/problem/D

【题意】



给你一个字符串;

里面只包括a和b;

让你把里面的”ab”子串全都去掉;

方式是,

每次操作可以把”ab”替换成为”bba”;

直到整个字符串里面没有”ab”子串为止

【题解】



从ab开始

ab->bba

左边再加一个a的话

即aab

就相当于在bba左边加了一个a

abba

->

bbaba

bbbbaa

会发现就是最左边那个a一直在往右走;

更一般的;

会发现

每次b前面有x个a

则答案递增2 x −1 

且这里的a会一直保留下去;

因为每次,所有的a都会跑到最右边去;

所以,遇到a就累加a的个数cnt;

遇到b就累加答案2 cnt −1 

可以预处理出2^x;

也可以用快速幂求。





【Number Of WA】



0



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1e6+100;
const LL MOD = 1e9+7; LL ksm(int y)
{
LL t = 1,x = 2;
while (y)
{
if (y&1) t = (t*x)%MOD;
x = (x*x)%MOD;
y>>=1;
}
return t;
} char s[N]; int main()
{
//freopen("F:\\rush.txt","r",stdin);
ios::sync_with_stdio(false),cin.tie(0);//scanf,puts,printf not use
cin >> (s+1);
int len = strlen(s+1);
int numa = 0;
LL ans = 0;
rep1(i,1,len)
if (s[i]=='a')
numa++;
else
ans=(ans+(ksm(numa)-1)%MOD)%MOD;
cout << ans << endl;
return 0;
}

【codeforces 805D】Minimum number of steps的更多相关文章

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

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

  2. 【Codeforces 1086B】Minimum Diameter Tree

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 统计叶子节点个数m 把每条和叶子节点相邻的边权设置成s/cnt就可以了 这样答案就是2*s/m(直径最后肯定是从一个叶子节点开始,到另外一个叶 ...

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

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

  4. Codeforces 805 D Minimum number of steps

    题意: 给定一串字符串,将所有“ab”的子串替换为“bba”,询问多少次操作后没有子串“ab”. 分析: 观察可得,将“ab”替换为“bba”有两种结果. ①a移到了b的后面 ②增加了一个b 而且最终 ...

  5. Codeforces 805D - Minimum number of steps

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

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

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

  9. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

随机推荐

  1. cocos2dx 3.1从零学习(二)——菜单、场景切换、场景传值

    回想一下上一篇的内容,我们已经学会了创建一个新的场景scene,加入sprite和label到层中.掌握了定时事件schedule. 我们能够顺利的写出打飞机的主场景框架. 上一篇的内容我练习了七个新 ...

  2. 从OTF字体文件里查找字体名称

    for in ? 使用神器vim就好了. . . vim ./AKZIDENZGROTESK-COND.OTF

  3. Codeforces Round #200 (Div. 2)D. Alternating Current (堆栈)

    D. Alternating Current time limit per test 1 second memory limit per test 256 megabytes input standa ...

  4. Chrome改动浏览器User Agent

    对浏览器快捷方式右键->改动目标项为 C:\Users\LJ\AppData\Local\Google\Chrome\Application\chrome.exe --user-agent=&q ...

  5. luogu1967 货车运输 最大瓶颈生成树

    题目大意 给出一张图,给出q对点,求这两个点间权值最小边最大的路径,输出这个最小边权. 题解 我们先一条一条边建图.当建立的边使得图中形成环时,因为环中的每个节点只考虑是否连通和瓶颈大小,要想互相连通 ...

  6. luogu2774 方格取数问题 二分图最小权点覆盖集

    题目大意:在一个有 m*n 个方格的棋盘中,每个方格中有一个正整数.现要从方格中取数,使任意 2 个数所在方格没有公共边,输出这些数之和的最大值. 思路:这种各个点之间互相排斥求最大值的题,往往需要利 ...

  7. href 与 src

    href:常用有两个标签<a>和<link> 1.<a href="http://www.w3school.com.cn">W3School&l ...

  8. 腾讯新闻多图jQuery相册展示效果代码

    腾讯新闻多图jQuery相册代码,带左右切换箭头,带缩略图,可左右切换,点击缩略图展示原图. 在线演示本地下载

  9. dataAdapter

    public static class DataAdapter { /// <summary> /// DataRow转换成Hash对象 /// </summary> /// ...

  10. Service、chkconfig命令

    转自:http://my.oschina.net/phptiger86/blog/137656