题目链接:http://codeforces.com/contest/805/problem/D 题意:只有一个操作就是将ab变成bba直到不能变为止,问最少边几次. 题解:这题可以多列几组来找规律,事实上是可以递推的,递推可得到一个式子 a[n]=2*a[n-1]+1,然后化成通项公式. a[n]+1=2*(a[n-1]+1),a[n]+1=2^n,a[n]=2^n-1; 然后就可以解决b前面有几个a的问题了,ab=2^1-1,aab=2^2-1, #include <iostream> #…
题意: 给定一串字符串,将所有“ab”的子串替换为“bba”,询问多少次操作后没有子串“ab”. 分析: 观察可得,将“ab”替换为“bba”有两种结果. ①a移到了b的后面 ②增加了一个b 而且最终的结果一定是前面全是b,后面全是a. 所以可以猜想从后往前数,设置一个B_cnt, 每当碰到一个b, 就b_cnt++, 碰到A, 就先加上一个b_cnt(因为每替换一次会将a移动后一格,所以要替换b_cnt次),再将b_cnt*2(多出b_cnt个b). #include <cstdio> #i…
[题目链接]:http://codeforces.com/contest/805/problem/D [题意] 给你一个字符串; 里面只包括a和b; 让你把里面的"ab"子串全都去掉; 方式是, 每次操作可以把"ab"替换成为"bba"; 直到整个字符串里面没有"ab"子串为止 [题解] 从ab开始 ab->bba 左边再加一个a的话 即aab 就相当于在bba左边加了一个a abba -> bbaba bbbba…
传送门: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…
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()…
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…
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,…
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…