[Updating] Codeforces Round #411 解题报告

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

(N1)/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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值