【推导】Codeforces Round #411 (Div. 1) B. Minimum number of steps
最后肯定是bbbb...aaaa...这样。
你每进行一系列替换操作,相当于把一个a移动到右侧。
会增加一些b的数量……然后你统计一下就行。式子很简单。
喵喵喵,我分段统计的,用了等比数列……感觉智障。一个a一个a地统计答案即可。
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
#define MOD 1000000007ll
typedef long long ll;
ll Quick_Pow(ll a,ll p)
{
if(!p) return 1;
ll ans=Quick_Pow(a,p>>1);
ans=ans*ans%MOD;
if((p&1)==1) ans=(ans*(a%MOD))%MOD;
return ans;
}
ll ans;
char s[1000010];
int lastb,n;
int main(){
// freopen("b.in","r",stdin);
scanf("%s",s+1);
n=strlen(s+1);
for(int i=n;i>=1;--i){
if(s[i]=='b'){
lastb=i;
break;
}
}
ll a1=0;
for(int i=lastb;i>=1;){
int j;
for(j=i;j>=1;--j){
if(j==1 && s[j]=='b'){
cout<<ans<<endl;
return 0;
}
else if(s[j]=='a'){
break;
}
}
for(int k=j;k>=1;--k){
if(k==1&&s[k]=='a' || s[k-1]=='b'){
a1=(a1+(ll)(i-j))%MOD;
ans=(ans+(a1*(Quick_Pow(2ll,(ll)(j-k+1))-1ll+MOD)%MOD)%MOD)%MOD;
a1=(a1*Quick_Pow(2ll,(ll)(j-k+1)))%MOD;
i=k-1;
break;
}
}
}
cout<<ans<<endl;
return 0;
}
【推导】Codeforces Round #411 (Div. 1) B. Minimum number of steps的更多相关文章
- 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 ...
- Codeforces Round #411 (Div. 2)(A,B,C,D 四水题)
A. Fake NP time limit per test:1 second memory limit per test:256 megabytes input:standard input out ...
- Codeforces Round #411 (Div. 2)
来自FallDream的博客,未经允许,请勿转载,谢谢. 由于人傻又菜 所以这次又滚去div2了 一堆结论题真的可怕 看见E题不是很有思路 然后就去大力搞F题 T了最后一个点 真的绝望 但 ...
- Codeforces Round #411 (Div. 2) 【ABCDE】
A. Fake NP 题意:给你l,r,让你输出[l,r]里面除1以外的,出现因子数量最多的那个数. 题解:如果l==r输出l,否则都输出2 #include<bits/stdc++.h> ...
- Codeforces Round #411 (Div. 2) A-F
比赛时候切了A-E,fst了A Standings第一页只有三个人挂了A题,而我就是其中之一,真™开心啊蛤蛤蛤 A. Fake NP time limit per test 1 second memo ...
- Codeforces Round 411 Div.2 题解
A Fake NP standard input/output s, MB Submit Add to favourites x3673 B -palindrome standard input/ou ...
- Codeforces Round #427 (Div. 2) B. The number on the board
引子: A题过于简单导致不敢提交,拖拖拉拉10多分钟还是决定交,太冲动交错了CE一发,我就知道又要错过一次涨分的机会.... B题还是过了,根据题意目测数组大小开1e5,居然蒙对,感觉用vector更 ...
- 【推导】Codeforces Round #411 (Div. 1) A. Find Amir
1 2 3 4 5 6 7 4-5-3-6-2-7-1 答案是(n-1)/2 #include<cstdio> using namespace std; int n; int main() ...
- Codeforces Round #283 (Div. 2) A. Minimum Difficulty 暴力水题
A. Minimum Difficulty time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
随机推荐
- node.js 开发命令行工具 发布npm包
新建一个文件夹“nodecmd”: 在nodecmd下新建文件夹bin: 在bin文件夹下新建JavaScript文件hello.js #!/usr/bin/env node console.log( ...
- webpack_配置和使用教程
webpack是一个模块打包的工具,它的作用是把互相依赖的模块处理成静态资源. webpack 可以使用 loader 来预处理文件.这允许你打包除 JavaScript 之外的任何静态资源.你可以使 ...
- 8.0docker的客户端和守护进程
C/S 链接的方式 unix:///var/run/docker.sock 默认的 tcp://host:port fd://socketfd 在linux上进行socket 模拟 nc -U /va ...
- python碎片记录(一)
1.python中求幂运算 2**31-1 2的31次方减一(32位整型数据范围为-2^31~2^31-1,最高位为符号位,负向值比正向值绝对值大1) 2.python中整数除法 x=x//1 ...
- ms17010利用失败解决一则
没有反弹得到session并且提示如下: [-] 10.0.131.2:445 - Service failed to start, ERROR_CODE: 216 换了一个payload set p ...
- Python3 PyPAML 模块(配置文件的操作)
YAML 是专门用来写配置文件的语言,非常简洁和强大 它的基本语法规则如下: 1.大小写敏感 2.使用缩进表示层级关系 3.缩进时不允许使用Tab键,只允许使用空格. 4.缩进的空格数目不重要,只要相 ...
- LINUX中断学习笔记【转】
转自:http://blog.chinaunix.net/uid-14825809-id-2381330.html 1.中断的注册与释放: 在 , 实现中断注册接口: int request_irq( ...
- kernel defconfig
Some defconfig files are placed on below path. Only one *_defconfig can be selected. android/kernel/ ...
- python基础===继承和多继承
继承 class A: def spam(self): print("A.SPAM") def add(self, x,y): return x+y class B(A): def ...
- 文件上传实现ajax假异步
$.ajaxFileUpload({ url : getSitePath()+'/jlyElderly/doUpdateImage', secureuri : false,//是否需要安全协议 fil ...