【推导】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 ...
随机推荐
- 你自认为理解了JavaScript?【转】
第一题 if (!("a" in window)) { var a = 1; } alert(a); 第二题 var a = 1, b = function a(x) { x &a ...
- Exception 和 Error 包结构
- KVM虚拟机建立快照
部分转载: http://blog.csdn.net/gg296231363/article/details/6899533 windows虚拟机默认镜像格式为raw,快照默认格式为qcow2.win ...
- 如何在苹果官网下载旧版本的Xcode
如何在苹果官网下载旧版本的Xcode 前段时间XcodeGhost事件让很多应用中招,不乏一些知名的互联网公司开发的应用.事件的起因是开发者使用了非官方的Xcode,这些Xcode带有xcodegho ...
- 对list对象进行排序
List<LjlSevOrdersVO> list = ljlSevOrdersService.findSevForOrders(ljlSevOrdersVO); //查出所有是自愿者的订 ...
- Palindrome Partitioning——回溯算法的又一经典
Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...
- Windows7 + OSG3.6 + VS2017 + Qt5.11
一.准备工作 下载需要的材料: 1. OSG稳定版源代码, 3.6.3版本 2. 第三方库,选择VS2017对应的版本 https://download.osgvisual.org/3rdParty ...
- JQuery 获取页面某一元素的位置
获取页面某一元素的绝对X,Y坐标 var X = $('#ElementID').offset().top; var Y = $('#ElementID').offset().left; 获取相对(父 ...
- JAVA用POI读取和创建2003和2007版本Excel
1.添加maven依赖 <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-o ...
- 六十三 、异步IO
在IO编程一节中,我们已经知道,CPU的速度远远快于磁盘.网络等IO.在一个线程中,CPU执行代码的速度极快,然而,一旦遇到IO操作,如读写文件.发送网络数据时,就需要等待IO操作完成,才能继续进行下 ...