【推导】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 ...
随机推荐
- js中的document.ready
1.概念 表示在dom结构绘制完成后执行,可能DOM元素关联的部分并未加载完 2.写法 $(document).on("ready",function(){ }) $(docume ...
- Python3 高阶函数
高阶函数 (满足其一就是:(1)一个函数名作为另一个函数的形参:(2)返回值包含函数名;不修改函数的调用方式) 1.一个函数名作为另一个函数的形参 输出结果: 2.返回值包含函数名;不修改函数的 输出 ...
- mysql之基本数据库操作(二)
环境信息 数据库:mysql-5.7.20 操作系统:Ubuntu-16.04.3 mysql的启动.退出.重启 # 启动 $ sudo service mysqld start # 停止 $ sud ...
- jQuery Validate插件 验证实例
官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-validation Validate手册: http://www.cnblogs.co ...
- selenium===requestium模块介绍
有时,你可能会在网上实现一些自动化操作.比如抓取网站,进行应用测试,或在网上填表,但又不想使用API,这时自动化就变得很必要.Python提供了非常优秀的Requests库可以辅助进行这些操作.可惜, ...
- python实战===一句python代码搭建FTP服务
环境搭建: python windows/linux pip install pyftpdlib (安装失败请到这里下载:https://pypi.python.org/pypi/pyftpdlib ...
- Unsupported gpu architecture 'compute_20'
NVCC src/caffe/layers/reduction_layer.cunvcc fatal : Unsupported gpu architecture 'compute_20'Make ...
- Mac OSX下Appium驱动iPhone真机
1.安装Xcode.Command Line Tools和Appium. 2.安装brew:/usr/bin/ruby -e "$(curl -fsSL https://raw.github ...
- 用Python写个自动ssh登录远程服务器的小工具
很多时候我们喜欢在自己电脑的终端直接ssh连接Linux服务器,而不喜欢使用那些有UI界面的工具区连接我们的服务器.可是在终端使用ssh我们每次都需要输入账号和密码,这也是一个烦恼,所以我们可以简单的 ...
- 获取windows 网卡GUID和ip信息
# coding: UTF-8 import _winreg GUID=dict() num = 0 netCfgInstanceID = None hkey = _winreg.OpenKey(_w ...