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 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 10^9 + 7.
The string "ab" appears as a substring if there is a letter 'b' right after the letter 'a' somewhere in the string.
the initial string consisting of letters 'a' and 'b' only with length from 1 to 10^6.
大意:
给一个ab串,你每次能挑一个ab变成bba,问至少变多少次不能再变
串长1e6,答案膜1e9+7
b……bba?
我就是叫紫妈怎么了?
恩核心思路就是ab变成bba后相当于把a往右挪了一下并在a前面添加一个b
这样就好写了从右往左扫,如果遇到b就把b的个数+1,如果遇到a就把答案加上a后面b的个数并把b的个数翻倍
因为是从右往左扫的,这样就保证a往右挪的时候为后面的a添加的b的个数尽可能少,保证答案最小
不需要考虑一串a连在一起的情况,如果最右边全是a,那么不用管了对答案没贡献,就算左边的a挪过去也越不过这一串a
如果中间是一串a,那么右端点一定接了一个b,最右边的a挪过去后次右边又接上了b,这样就能保证所有的a都能挪到末尾
代码很好写,python13行(没压行,写的比较散
代码:
mo =
a = raw_input()
b, c = ,
i = len(a) -
while i >= :
if a[i] == 'a':
c = (c + b) % mo
b = (b * ) % mo
else:
b = (b + ) % mo
i = i - print c
codeforce 804B Minimum number of steps的更多相关文章
- Codeforces 805D/804B - Minimum number of steps
传送门:http://codeforces.com/contest/805/problem/D 对于一个由‘a’.‘b’组成的字符串,有如下操作:将字符串中的一个子串“ab”替换成“bba”.当字符串 ...
- 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 ...
- 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 ...
- Minimum number of steps 805D
http://codeforces.com/contest/805/problem/D D. Minimum number of steps time limit per test 1 second ...
- Codeforces 805D - Minimum number of steps
805D - Minimum number of steps 思路:简单模拟,a每穿过后面一个b,b的个数+1,当这个a穿到最后,相当于把它后面的b的个数翻倍.每个a到达最后的步数相当于这个a与它后面 ...
- 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 ...
- 【codeforces 805D】Minimum number of steps
[题目链接]:http://codeforces.com/contest/805/problem/D [题意] 给你一个字符串; 里面只包括a和b; 让你把里面的"ab"子串全都去 ...
- 【推导】Codeforces Round #411 (Div. 1) B. Minimum number of steps
最后肯定是bbbb...aaaa...这样. 你每进行一系列替换操作,相当于把一个a移动到右侧. 会增加一些b的数量……然后你统计一下就行.式子很简单. 喵喵喵,我分段统计的,用了等比数列……感觉智障 ...
- 【贪心】codeforces D. Minimum number of steps
http://codeforces.com/contest/805/problem/D [思路] 要使最后的字符串不出现ab字样,贪心的从后面开始更换ab为bba,并且字符串以"abbbb. ...
随机推荐
- unity实现用鼠标右键控制摄像机视角上下左右移动
using System;using System.Collections.Generic;using UnityEngine;public class ViewControl{ enum Rotat ...
- java获得当前系统时间三种方法
参见: http://blog.csdn.net/cloume/article/details/46624637
- Java使用POI插件将数据以excel形式备份
将数据以表格形式进行备份 (1)导入poi的jar包 放入lib下: WebRoot\WEB-INF\lib\poi-3.2-FINAL-20081019.jar 下载链接:https://gith ...
- PropertiesUtil 获取文件属性值
有时候不要把一些属性值写死在代码中,而是写在配置在文件中,方便更改 PropertiesUtil工具类:读取key-value形式的配置文件,根据key获得value值 1.测试类 public c ...
- JavaScript+CSS+DIV实现表格变色示例
<!DOCTYPE html> <html> <head> <title>colortable.html</title> <scrip ...
- [PyImageSearch] Ubuntu16.04下针对OCR安装Tesseract
今天的博文是安装和使用光学字符识别(OCR)的Tesseract库的两部分系列的第一部分. 本系列的第一部分将着重于在您的机器上安装和配置Tesseract,然后使用tesseract命令将OCR应用 ...
- 关于对Access数据库的学习报告
学习Access数据库的报告 一.前言 一开始我对access一窍不通,甚至不知道它是干什么的,后来经过网上资料的查阅对它略有了解.microsoft office access是由微软发布的关联式数 ...
- 2019.3.5 L261 Are All Our Organs Vital?
Medicine has not always shown a lot of respect for the human body. Just think about the ghoulish dis ...
- springsecurity基于数据库验证用户
之前的springsecurity程序都是将数据存放在内存中的,通过 <security:user-service> <security:user name="user&q ...
- idea本地安装 lombok插件
转:https://blog.csdn.net/weixin_41404773/article/details/80689639 idea本地安装 lombok插件 项目中经常使用bean,entit ...