D. Minimum number of steps

time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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 modulo 109 + 7.
The string "ab" appears as a substring if there is a letter 'b' right after the letter 'a' somewhere in the string.
Input
The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106.
Output
Print the minimum number of steps modulo 109 + 7.
Examples
input
ab
output
1
input
aab
output
3
Note
The first example: "ab"  →  "bba".
The second example: "aab"  →  "abba"  →  "bbaba"  →  "bbbbaa".
 
解题思路:
题意是输入一个字符串,将其中的ab改为bba,问需要变换多少次才能让字符串中没有ab
由题可知,ab判断两种情况: 1.ab前面有a时的变化, 2.ab后面有b时的变化;
具体解析放在代码中解释
 
实现代码:
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
char str[];
int main(){
int n,total,a;
scanf("%s",str);
total = a = ;
int len = strlen(str);
for(int i = ;i < len;i++){
if(str[i] == 'a'){ //由于只有a,b两个字母,只需判断是否为a
a = ( * a + ) % mod; //由于数据太大,只能一步一步取模,若将b前面的a个数加起来用2^n-1公式求值,数字会由于太大,变成负数
}else{
total = (total + a) % mod; //公式可自行推演,多推一下,很容易得出
}
}
printf("%d\n",total);
return ;
}

Codeforces Round #411 div 2 D. Minimum number of steps的更多相关文章

  1. 【推导】Codeforces Round #411 (Div. 1) B. Minimum number of steps

    最后肯定是bbbb...aaaa...这样. 你每进行一系列替换操作,相当于把一个a移动到右侧. 会增加一些b的数量……然后你统计一下就行.式子很简单. 喵喵喵,我分段统计的,用了等比数列……感觉智障 ...

  2. Codeforces Round #411 (Div. 2)(A,B,C,D 四水题)

    A. Fake NP time limit per test:1 second memory limit per test:256 megabytes input:standard input out ...

  3. Codeforces Round #411 (Div. 2)

    来自FallDream的博客,未经允许,请勿转载,谢谢. 由于人傻又菜 所以这次又滚去div2了  一堆结论题真的可怕 看见E题不是很有思路   然后就去大力搞F题  T了最后一个点 真的绝望   但 ...

  4. Codeforces Round #411 (Div. 2) 【ABCDE】

    A. Fake NP 题意:给你l,r,让你输出[l,r]里面除1以外的,出现因子数量最多的那个数. 题解:如果l==r输出l,否则都输出2 #include<bits/stdc++.h> ...

  5. Codeforces Round #411 (Div. 2) A-F

    比赛时候切了A-E,fst了A Standings第一页只有三个人挂了A题,而我就是其中之一,真™开心啊蛤蛤蛤 A. Fake NP time limit per test 1 second memo ...

  6. Codeforces Round 411 Div.2 题解

    A Fake NP standard input/output s, MB Submit Add to favourites x3673 B -palindrome standard input/ou ...

  7. Codeforces Round #427 (Div. 2) B. The number on the board

    引子: A题过于简单导致不敢提交,拖拖拉拉10多分钟还是决定交,太冲动交错了CE一发,我就知道又要错过一次涨分的机会.... B题还是过了,根据题意目测数组大小开1e5,居然蒙对,感觉用vector更 ...

  8. Codeforces Round #283 (Div. 2) A. Minimum Difficulty 暴力水题

    A. Minimum Difficulty time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  9. Codeforces Round #411 (Div. 2) C. Find Amir

    C. Find Amir time limit per test   1 second memory limit per test   256 megabytes   A few years ago ...

随机推荐

  1. 16-(基础入门篇)GPRS(Air202)关于多个文件中的变量调用和定时器

    https://www.cnblogs.com/yangfengwu/p/9968405.html 因为自己看到好多问多个文件调用的,感觉这个应该说一说 对了大家有没有知道这个是干什么的 大家有没有看 ...

  2. Android之TCP服务器编程

    推荐一个学java或C++的网站http://www.weixueyuan.net/,本来想自己学了总结出来再写博客,现在没时间,打字太慢!!!!,又想让这好东西让许多人知道. 关于网络通信:每一台电 ...

  3. STM32 printf()函数和scanf()函数重定向到串口

    STM32 printf()函数和scanf()函数重定向到串口 printf()函数和scanf()函数重定向 在学习STM32的时候,常常需要用串口来测试代码的正确与否,这时候就要要用到print ...

  4. python 知识2

    零. type()函数怎么使用 type()的使用方法:type(对象)type()是接收一个对象当做参考,之后反回对象的相应类型.>>>type(1)<type 'int'& ...

  5. CF1110G Tree-Tac-Toe 博弈论、构造

    传送门 UPD:之前可能对白色变无色的过程讲的不是很清楚,已经补充 显然在双方绝顶聪明的情况下,黑色不可能赢 首先考虑树上一个白色的点都没有的情况: 1.如果树上有一个点的度数\(\geq 4\),白 ...

  6. CF613D Kingdom and its Cities 虚树

    传送门 $\sum k \leq 100000$虚树套路题 设$f_{i,0/1}$表示处理完$i$以及其所在子树的问题,且处理完后$i$所在子树内是否存在$1$个关键点满足它到$i$的路径上不存在任 ...

  7. java缓存技术的介绍

    一.什么是缓存1.Cache是高速缓冲存储器 一种特殊的存储器子系统,其中复制了频繁使用的数据以利于快速访问2.凡是位于速度相差较大的两种硬件/软件之间的,用于协调两者数据传输速度差异的结构,均可称之 ...

  8. @Pointcut的用法

    在Spring 2.0中,Pointcut的定义包括两个部分:Pointcut表示式(expression)和Pointcut签名(signature).让我们先看看execution表示式的格式: ...

  9. Ceph分布式存储集群-硬件选择

    在规划Ceph分布式存储集群环境的时候,对硬件的选择很重要,这关乎整个Ceph集群的性能,下面梳理到一些硬件的选择标准,可供参考: 1)CPU选择Ceph metadata server会动态的重新分 ...

  10. Let the Balloon Rise HDU水题

    题意 让你统计字符串最多的那个串,并输出 分析 直接用map统计,不断更新最大值即可 代码 #include<iostream> #include<algorithm> #in ...