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代码: #i…
思路: 找规律.参考了http://blog.csdn.net/harlow_cheng/article/details/71190999. 实现: #include <iostream> using namespace std; ; int main() { string s; cin >> s; int n = s.length(); ; ; ; i < n; i++) { % mod; ) % mod; } cout << sum << endl…
D. Minimum number of steps time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of s…
D. Minimum number of steps time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of s…
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,…
http://codeforces.com/contest/805/problem/D D. Minimum number of steps time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output We have a string of letters 'a' and 'b'. We want to perform some opera…
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; ; ; int main()…
D. Minimum number of steps time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of s…
[题目链接]:http://codeforces.com/contest/805/problem/D [题意] 给你一个字符串; 里面只包括a和b; 让你把里面的"ab"子串全都去掉; 方式是, 每次操作可以把"ab"替换成为"bba"; 直到整个字符串里面没有"ab"子串为止 [题解] 从ab开始 ab->bba 左边再加一个a的话 即aab 就相当于在bba左边加了一个a abba -> bbaba bbbba…
最后肯定是bbbb...aaaa...这样. 你每进行一系列替换操作,相当于把一个a移动到右侧. 会增加一些b的数量……然后你统计一下就行.式子很简单. 喵喵喵,我分段统计的,用了等比数列……感觉智障.一个a一个a地统计答案即可. #include<cstdio> #include<cstring> #include<iostream> using namespace std; #define MOD 1000000007ll typedef long long ll;…