805D - Minimum number of steps

思路:简单模拟,a每穿过后面一个b,b的个数+1,当这个a穿到最后,相当于把它后面的b的个数翻倍。每个a到达最后的步数相当于这个a与它后面已经到达最后的a之间的b的个数,只要从后面往前扫,记录b的个数,每遇到一个a,把b的个数加入答案,并且b的个数翻倍。

代码:

#include<bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f;
const int N=1e6+;
const int MOD=1e9+; int main()
{
ios::sync_with_stdio(false);
cin.tie();
string s;
cin>>s;
int l=s.size();
int ans=,sum=;
for(int i=l-;i>=;i--)
{
if(s[i]=='b')sum++;
else if(s[i]=='a')ans=(ans+sum)%MOD,sum=(sum+sum)%MOD;
}
cout<<ans<<endl;
return ;
}

Codeforces 805D - Minimum number of steps的更多相关文章

  1. 【贪心】codeforces D. Minimum number of steps

    http://codeforces.com/contest/805/problem/D [思路] 要使最后的字符串不出现ab字样,贪心的从后面开始更换ab为bba,并且字符串以"abbbb. ...

  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. Minimum number of steps 805D

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

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

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

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

  7. 【codeforces 805D】Minimum number of steps

    [题目链接]:http://codeforces.com/contest/805/problem/D [题意] 给你一个字符串; 里面只包括a和b; 让你把里面的"ab"子串全都去 ...

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

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

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

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

随机推荐

  1. EPD的驱动

    整个e-ink技术的生产流程:1997年从MIT媒体实验室走出来的E-INK公司成立并专注于研发具有良好阅读体验的电子纸.其中最著名的产品就是Vizplex 电子墨水.E-INK提供电子墨水给Pane ...

  2. uva10003

    /* 2014.3.6 这题说的是给你了一根木棒 然后 n 个点(线段上的点) 然后计算 在这 n个点上都切下去的 最小花费 举个例子 100 3 25 50 75 如果 从 25 开始切 然后切 5 ...

  3. [转]Mac Appium环境安装

    原文:https://blog.csdn.net/dongqiushan/article/details/53326518 1.安装JDK; 2.安装Android SDK; 3.安装brew; 4. ...

  4. 调用spark API,监控任务的进度

    我们现在需要监控datapre0这个任务每一次执行的进度,操作如下: 1. 如图所示,打开spark管理页面,找到对应的任务,点击任务名datapre0 2. 进去之后,获得对应IP和端口  3. 访 ...

  5. Linux服务器配置---phpmyadmin

    phpMyAdmin 工具 1.检测是否已安装php.php-mysql.apache等工具 [root@localhost src]# rpm -qa |grep php php-cli-5.3.3 ...

  6. 微信小程序的功能开发工具跟公众号的差别,小程序是一种减负思维对简单APP是巨大打击

    微信小程序的功能开发工具跟公众号的差别,小程序是一种减负思维对简单APP是巨大打击 摘要: 小程序和公众号最大的区别有如下四点:1.小程序没有粉丝,开发者在后台能看到的只能是累计用户访问数以及实时统计 ...

  7. Qt中layout()->setSizeConstraint(QLayout::SetFixedSize);崩溃的问题

    编译环境: win764位,vs2008编译器,cbd调试器,qt4.8 背景: 按照<C++ Gui Qt4编程>书中第二章的一个例子(sortDialog)一步步抄完,编译运行,显示不 ...

  8. C/C++之内存分配

    一.编译时与运行时的内存情况1.编译时不分配内存编译时是不分配内存的.此时只是根据声明时的类型进行占位,到以后程序执行时分配内存才会正确.所以声明是给编译器看的,聪明的编译器能根据声明帮你识别错误.2 ...

  9. Spring Boot 踩坑之路之 Configuration Annotation Proessor not found in classpath

    1. 出现spring boot Configuration Annotation Proessor not found in classpath的提示是在用了@ConfigurationProper ...

  10. P2P原理及UDP穿透简单说明

    转:http://http://andylin02.iteye.com/blog/444666 P2P原理及UDP穿透简单说明 本文章出自cnntec.com的AZ猫著,如需要转发,请注明来自cnnt ...