码迷,mamicode.com
首页 > 其他好文 > 详细

汕头市队赛 C KMP codeforces B. Image Preview

时间:2017-07-02 11:38:16      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:pre   tar   ref   contest   ret   sed   int   targe   blog   

汕头市队赛题目传送门

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("\n");
    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\n",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\n",ans);
    return 0;
}
View Code

 

汕头市队赛 C KMP codeforces B. Image Preview

标签:pre   tar   ref   contest   ret   sed   int   targe   blog   

原文地址:http://www.cnblogs.com/lyzuikeai/p/7105413.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!