洛谷 CF804B Minimum number of steps
嗯...
题目链接: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的更多相关文章
- CF804B Minimum number of steps
思路: 找规律.参考了http://blog.csdn.net/harlow_cheng/article/details/71190999. 实现: #include <iostream> ...
- 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 ...
- 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 ...
- 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 ...
- 洛谷——P1348 Couple number
P1348 Couple number 题目描述 任何一个整数N都能表示成另外两个整数a和b的平方差吗?如果能,那么这个数N就叫做Couple number.你的工作就是判断一个数N是不是Couple ...
- 洛谷 P1348 Couple number
题目描述 任何一个整数N都能表示成另外两个整数a和b的平方差吗?如果能,那么这个数N就叫做Couple number.你的工作就是判断一个数N是不是Couple number. 输入输出格式 输入格式 ...
随机推荐
- springboot引入Oracle依赖
最近学习spring boot,在网上找一些项目学习,有的项目引入了oracle驱动包,自己搭建一直不成功,百度发现说是权限问题无法下载. 然后参考下面博客终于解决:springboot引入Oracl ...
- 使用git pull同步github代码到服务器
我直接用git pull的时候遇到这个错误: error: Your local changes to the following files would be overwritten by merg ...
- springboot中druid监控的配置(DruidConfiguration)
当数据库连接池使用druid 时,我们进行一些简单的配置就能查看到sql监控,web监控,url监控等等. 以springboot为例,配置如下 import com.alibaba.druid.su ...
- MyBatis Generator 超详细配置
想快速开始,请直接拉到最后,看整体配置. MyBatis Generator 是 MyBatis 提供的一个代码生成工具.可以帮我们生成 表对应的持久化对象(po).操作数据库的接口(dao).CRU ...
- if a != None:
>>> x = 1 >>> not x False >>> x = [1] >>> not x False >>&g ...
- Qt核心剖析:信息隐藏
原文 http://devbean.blog.51cto.com/448512/326686 (一) 如果你阅读了 Qt 的源代码,你会看到一堆奇奇怪怪的宏,例如 Q_D,Q_Q.我们的Qt源码之旅就 ...
- Java - 字符串操作
字符串常用操作如下 public static void main(String[] args) { /** * 创建字符串 */ String s1="zifuchuan123" ...
- C++ 宏定义创建(销毁)单例
Util.h: #define CREATE_SINGLETON_POINTER(CLASS,INSTANCE,MUTEX) if (NULL == INSTANCE) \ { \ MUTEX.loc ...
- IDEA中编辑HTML格式,不自动缩进问题
在IntelliJ Idea中HTML格式化时,默认<head><body>以及<body>下的标签都不会缩进,这就导致你每次写好html时候格式化的时候所有标签都 ...
- 吴裕雄 python 神经网络——TensorFlow 循环神经网络处理MNIST手写数字数据集
#加载TF并导入数据集 import tensorflow as tf from tensorflow.contrib import rnn from tensorflow.examples.tuto ...