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

Codeforces Round #418 (Div. 2) C. An impassioned circulation of affection(双指针)

时间:2017-06-27 15:00:51      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:splay   style   view   一个   turn   ssi   color   r++   tar   

题目链接:Codeforces Round #418 (Div. 2) C. An impassioned circulation of affection

题意:

给你一个字符串,有q个询问,每个询问一个x和一个字符 o。

现在让你在原来的字符串上最多改变x个字符,问能构成最长的o子串的长度。

题解:

一共有26*1500种状态,对于每个状态用双指针滚一滚就行了。

技术分享
 1 #include<bits/stdc++.h>
 2 #define F(i,a,b) for(int i=(a);i<=(b);++i)
 3 using namespace std;
 4 
 5 const int N=1507;
 6 int ans[27][N],n,k,x;
 7 char s[N],o[2];
 8 
 9 int del(int i,int j)
10 {
11     int ans=0;
12     for(int l=1,r=1,cnt=0;r<=n;r++)
13     {
14         cnt+=s[r]!=j;
15         if(cnt<=i)ans=max(ans,r-l+1);
16         while(l<=r&&cnt==i+1)cnt-=s[l]!=j,l++;
17     }
18     return ans;
19 }
20 
21 int main(){
22     scanf("%d%s",&n,s+1);
23     F(i,1,n)s[i]-=a;
24     F(i,0,25)F(j,1,n)ans[i][j]=del(j,i);
25     scanf("%d",&k);
26     while(k--)
27     {
28         scanf("%d%s",&x,o),o[0]-=a;
29         printf("%d\n",ans[*o][x]);
30     }
31     return 0;
32 }
View Code

 

Codeforces Round #418 (Div. 2) C. An impassioned circulation of affection(双指针)

标签:splay   style   view   一个   turn   ssi   color   r++   tar   

原文地址:http://www.cnblogs.com/bin-gege/p/7084704.html

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