嗯...

题目链接:https://www.luogu.org/problemnew/show/CF804B

这道题没有什么技巧,只是一道找规律的题。

首先看到“ab”可以换成“bba”,所以首先要确定我们要逆序枚举(注意s从s_0开始),如果遇到a,则把ans += cntb,因为可以换的次数即为a后面b的个数,然后把cntb的个数乘二,因为一个ab可以换bba,也就一个b换两个b。如果遇到b,则直接cntb++即可,不需要别的操作。

注:mod可以随时模,不会影响最后结果。

AC代码:

 #include<cstdio>
#include<iostream>
#include<cstring> using namespace std; const int mod = 1e9 + ;
char s[];
long long ans, cntb; int main(){
scanf("%s", s);
int len = strlen(s);
for(int i = len - ; i >= ; i--){
if(s[i] == 'a'){
(ans += cntb) %= mod;
(cntb *= ) %= mod;
}
else cntb++;
}
printf("%lld\n", ans % mod);
return ;
}

AC代码

洛谷 CF804B Minimum number of steps的更多相关文章

  1. CF804B Minimum number of steps

    思路: 找规律.参考了http://blog.csdn.net/harlow_cheng/article/details/71190999. 实现: #include <iostream> ...

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

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

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

  5. Minimum number of steps 805D

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

  6. Codeforces 805D - Minimum number of steps

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

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

  8. 洛谷——P1348 Couple number

    P1348 Couple number 题目描述 任何一个整数N都能表示成另外两个整数a和b的平方差吗?如果能,那么这个数N就叫做Couple number.你的工作就是判断一个数N是不是Couple ...

  9. 洛谷 P1348 Couple number

    题目描述 任何一个整数N都能表示成另外两个整数a和b的平方差吗?如果能,那么这个数N就叫做Couple number.你的工作就是判断一个数N是不是Couple number. 输入输出格式 输入格式 ...

随机推荐

  1. codeforces 1245D(最小生成树)

    题面链接:https://codeforces.com/problemset/problem/1245/D 题意大概是给你一些城市的坐标,可以在城市中建立发电站,也可以让某个城市和已经建好发电站的城市 ...

  2. 229. 求众数 II

    Q: 给定一个大小为 n 的数组,找出其中所有出现超过 ⌊ n/3 ⌋ 次的元素. 说明: 要求算法的时间复杂度为 O(n),空间复杂度为 O(1). 示例 1: 输入: [3,2,3] 输出: [3 ...

  3. 动态路由协议 RIP

    RIP:Routing Information Protocol.RFC1058. 距离矢量协议:有间隔的多少和方向.传递的是路由条目.每个路由器不知道网络的完整拓扑结构,OSPF知道. 度量值:每种 ...

  4. Eugeny and Array(思维)

    Eugeny has array a = a1, a2, ..., an, consisting of n integers. Each integer ai equals to -1, or to ...

  5. (转)JSONObject的toBean 和 fromObject

    public static void main(String[] args) { Map map=new HashMap();map.put("我","妹"); ...

  6. [Reversal 剧情设计] 设定

    在正式写之前,先交代一些设定,便于后续的展开.先在这里说明一点,我的文笔可能很烂(因为在写小说方面还没有得到过别人的评价),只要你们能体会我想表达的东西就行(不过也的确是这样,如果作者构筑得过于详细, ...

  7. mybatis的8月29日

    一.select查询语句 1.mybatis的映射,jdbc预处理 <select id="selectPerson" parameterType="int&quo ...

  8. 【经典数据结构】B树与B+树的解释

    本文转载自:http://www.cnblogs.com/yangecnu/p/Introduce-B-Tree-and-B-Plus-Tree.html 前面讲解了平衡查找树中的2-3树以及其实现红 ...

  9. Python - 反向生成UML类图

    法一. pyreverse https://www.logilab.org/blogentry/6883 pip install pylint(集成在里面了) cd pack pyreverse -o ...

  10. 我的18vps~

    自从买了18vps的香港虚拟主机后,就面临一个问题,浏览器无法访问它的apache服务,后来发现,需要同时开启nginx服务: /usr/local/nginx/sbin/nginx -c /usr/ ...