CodeForces - 814C An impassioned circulation of affection

An impassioned circulation of affection
题 意:给你一串长度为n的字符串,q个询问,mi,ci。mi代表你可以修改字符的次数,ci代表修改后ci连续最长是多少。
数据范围:
1<=n<=1500
1<=q<=2e5
样例输入:

6
koyomi
3
1 o
4 o
4 m

样例输出:

3
6
5

思 路:连续的操作,可以考虑用尺取法。这题就是一个很裸的尺取法。
收 获:连续的操作,考虑用尺取。div2的abc题其实都不难,多思考,多总结

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e3+5;
map<int,int> mp;
int n,m;
char a[maxn];
int solve(int time,char ch[2]){
    int MAX = -1;
    int res = n+1;
    int s = 0,t = 0,ans=0;
    for(;;){
        while(t < n){
            if(a[t] == ch[0]){
                ans++;t++;
            }
            else if(time>0){
                time--;
                ans++;t++;
            }else if(time<=0){
                break;
            }
        }
        MAX = max(MAX,ans);
        if(t == n)return MAX;
        if(a[s] == ch[0]){
            ans--;
            s++;
        }else{
            ans--;
            s++;
            time++;
        }
    }
}
int main() {
    scanf("%d",&n);
    scanf("%s",a);
    scanf("%d",&m);
    int t;char ch[2];
    while(m--){
        scanf("%d %s",&t,ch);
        int MAX = solve(t,ch);
        printf("%d\n",MAX);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值