805A - Fake NP
除非L=R,否则2必定为答案之一
//Author: Lixiang
#include<stdio.h>
struct A{
int a,b;
void init(){
scanf("%d%d",&a,&b);
}
void work(){
if(a==b)printf("%d\n",a);
else puts("2");
}
}sol;
int main(){
sol.init();
sol.work();
return 0;
}
805B - 3-palindrome
简单构造
保证不出aaa或者bbb就行
//Author: Lixiang
#include<stdio.h>
#include<string>
#include<iostream>
using namespace std;
struct B{
int N;
void init(){
scanf("%d",&N);
}
void work(){
if(N==1){
puts("a");
return ;
}
string ans="aa";
for(int i=2;i<N;i++){
if(ans[i-2]=='a'){
ans+="b";
continue;
}
if(ans[i-2]=='b'){
ans+="a";
continue;
}
}
cout<<ans<<endl;
}
}sol;
int main(){
sol.init();
sol.work();
return 0;
}
804A - Find Amir
求
⌊(N−1)/2⌋
即可
//Author: Lixiang
#include<stdio.h>
struct C{
int N;
void init(){
scanf("%d",&N);
N--;
}
void work(){
printf("%d\n",N/2);
}
}sol;
int main(){
sol.init();
sol.work();
return 0;
}
804B - Minimum number of steps
因为一定不会出现ab所以目标字符串一定为若干个b接若干个a
贪心即可
//Author: Lixiang
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn=1000001;
const int mod=1000000007;
struct D{
long long bi[maxn];
char s[maxn];
void init(){
scanf("%s",s);
bi[0]=1;
for(int i=1;i<maxn;i++)
bi[i]=(bi[i-1]*2)%mod;
}
void work(){
int L=strlen(s);
long long bcnt=0,ans=0;
for(int i=L-1;i>=0;i--){
if(s[i]=='b'){
bcnt++;
if(bcnt==mod)bcnt=0;
continue;
}
ans=(ans+bcnt)%mod;
bcnt=(bcnt+bcnt)%mod;
}
printf("%I64d\n",ans);
}
}sol;
int main(){
sol.init();
sol.work();
return 0;
}