zoukankan      html  css  js  c++  java
  • 汕头市队赛 C KMP codeforces B. Image Preview

    汕头市队赛题目传送门

    codeforces题目传送门

    这道题我的做法是 尝试先往左走然后往右走 或者先往右走然后往左走 然后注意一下枚举顺序就okay啦

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #define LL long long
    using namespace std;
    const int M=1e6+7; 
    LL read(){
        LL ans=0,f=1,c=getchar();
        while(c<'0'||c>'9'){if(c=='-') f=-1; c=getchar();}
        while(c>='0'&&c<='9'){ans=ans*10+(c-'0'); c=getchar();}
        return ans*f;
    }
    int n,a,b,T;
    LL w[M],ans;
    char s[M];
    LL pd1(int l,int r){
        LL sum=w[r]-w[l-1];
        int now=(r-l)+(n+1-l);
        return sum+(LL)now*a;
    }
    LL pd2(int l,int r){
        LL sum=w[r]-w[l-1];
        int now=(r-l)+(r-n-1);
        return sum+(LL)now*a;
    }
    int main()
    {
        n=read(); a=read(); b=read(); T=read();
        scanf("%s",s+1); 
        for(int i=n+1;i<=2*n;i++) s[i]=s[i-n];
        for(int i=1;i<=2*n;i++) w[i]=(s[i]=='w'?(b+1):1)+w[i-1];
    //    for(int i=1;i<=2*n;i++) printf("%lld ",w[i]); printf("
    ");
        int l=n+1;
        for(int r=2*n;r>=n+1;r--){
            while(l>r-n+1&&pd1(l-1,r)<=T) l--;
            if(pd1(l,r)<=T) ans=max(ans,(LL)(r-l+1));
        }
        //printf("%lld
    ",ans);
        int r=n+1;
        for(int l=2;l<=n+1;l++){
            while(r<l+n-1&&pd2(l,r+1)<=T) r++;
            if(pd2(l,r)<=T) ans=max(ans,(LL)(r-l+1));
        }
    //    ans=min(ans,(LL)n);
        printf("%lld
    ",ans);
        return 0;
    }
    View Code
  • 相关阅读:
    JavaScript中的this相关
    Git进阶操作_1
    Git基本操作_5
    Git基本操作_4
    Git基本操作_3
    Git基本操作_2
    利用Python发送SMTP邮件
    Python JWT使用
    Python中的Asyncio 异步编程
    Python中的抽象类和接口类
  • 原文地址:https://www.cnblogs.com/lyzuikeai/p/7105413.html
Copyright © 2011-2022 走看看