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
  • 相关阅读:
    python 字符串常用操作
    markdown 基础语法
    网络安全入门的16个基本问题
    Linux中20个crontab例子
    使用python爬取一个网页里表格的内容
    浅谈python的深浅拷贝
    Linux中设置普通用户可以su和sudo
    iptables四表五链
    CentOS7编译安装NFS
    源码安装csvn
  • 原文地址:https://www.cnblogs.com/lyzuikeai/p/7105413.html
Copyright © 2011-2022 走看看