嗯...

题目链接: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. STL关联容器总结

    有序的都不带unordered,即如下: set multiset map multimap 其中带multi的表示关键字可以重复 无序的带unordered,如下: unordered_map un ...

  2. [MongoDB]MongoDB分页显示

    MongoDB Limit与Skip方法配合进行分页MongoDB Limit() 方法如果你需要在MongoDB中读取指定数量的数据记录,可以使用MongoDB的Limit方法,limit()方法接 ...

  3. SCROLLINFO结构详解

    在刚开始使用SCROLLINFO结构时感觉很不顺手,尤其其中的成员fMask理解不太深刻,经过查询资料才理解一二. 在使用滚动条功能时,如果要设置它的范围和位置可以用以前的函数,例如:SetScrol ...

  4. AcWing 847. 图中点的层次

    队列 #include <cstdio> #include <cstring> #include <iostream> #include <algorithm ...

  5. DVWA全级别之SQL Injection(SQL注入)

    DVWA全级别之SQL Injection(注入)   DVWA简介 DVWA(Damn Vulnerable Web Application)是一个用来进行安全脆弱性鉴定的PHP/MySQL Web ...

  6. 2019南昌网络赛 hello 2019

    这道题和一道2017,2016的类似. A string t is called nice if a string “2017” occurs in t as a subsequence but a ...

  7. Django视图层、模板层

    过滤器方法 upper 大写方式输出 add 给value加上一个数值 capfirst 第一个字母大写 center 输出指定长度的字符串,把变量居中 cut 删除指定字符串 date 格式化日期 ...

  8. next.config.js

    const configs = { // 编译文件的输出目录 distDir: 'dest', // 是否给每个路由生成Etag generateEtags: true, // 页面内容缓存配置 on ...

  9. 连接查询:inner join,left join,right join

    感谢原创:https://blog.csdn.net/plg17/article/details/78758593 准备工作: 1)新建两张表a_table和b_table: create table ...

  10. 如何安装和使用Maven

    今天我们来学习一下如何安装Maven,把步骤分享给大家,希望能对大家有帮助! 我的博客地址:https://www.cnblogs.com/themysteryofhackers/p/11996550 ...