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,…
传送门:http://codeforces.com/contest/805/problem/D 对于一个由‘a’.‘b’组成的字符串,有如下操作:将字符串中的一个子串“ab”替换成“bba”.当字符串中不含有子串“ab”时,任务完成.求完成任务的最小操作次数(mod109+7). 最终,字符串的形式为: bbb...baaa...a 可以考虑寻找规律: a. i)“ab”→“bba”, ii)“aab”→“abba”→“bbaba”→“bbbbaa”, iii)“aaab”→“aabba”→“a…
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…
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;…
http://codeforces.com/contest/805/problem/D [思路] 要使最后的字符串不出现ab字样,贪心的从后面开始更换ab为bba,并且字符串以"abbbb..."形式出现的话,那么需要替换的次数就是b的个数,并且b的个数会翻倍,因此遍历查找存在"ab”子串的位置,然后开始替换,并记录下每个位置开始及其后面b的个数,然后更新答案即可. [Accepted] #include <iostream> #include <stdio…