An impassioned circulation of affection(尺取+预处理)
题目链接:http://codeforces.com/contest/814/problem/C
题目:



题意:给你一个长度为n的字符串,m次查询,每次查询:最多进行k步修改,求字符c(要输入的字符)最长连续的长度。
思路:尺取法,预处理出每个字符连续长度为k需要的代价,然后O1查询。
代码实现如下:
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;;
typedef pair<int, int> pii;
typedef unsigned long long ull; #define lson i<<1
#define rson i<<1|1
#define bug printf("*********\n");
#define FIN freopen("D://code//in.txt", "r", stdin);
#define debug(x) cout<<"["<<x<<"]" <<endl;
#define IO ios::sync_with_stdio(false),cin.tie(0); const double eps = 1e-;
const int mod = ;
const int maxn = + ;
const double pi = acos(-);
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f; int n, q, x, cnt;
char s[maxn], c[];
int ans[][maxn]; int main() {
//FIN;
scanf("%d%s", &n, s);
for(int i = ; i < ; i++) {
for(int j = ; j < n; j++) {
cnt = ;
for(int k = j; k < n; k++) {
if(s[k] != 'a' + i) cnt++;
ans[i][cnt] = max(ans[i][cnt], k - j + );
}
}
for(int j = ; j <= n; j++) {
ans[i][j] = max(ans[i][j], ans[i][j-]);
}
}
scanf("%d", &q);
while(q--) {
scanf("%d%s", &x, c);
int num = c[] - 'a';
printf("%d\n", ans[num][x]);
}
return ;
}
An impassioned circulation of affection(尺取+预处理)的更多相关文章
- codeforces 814 C. An impassioned circulation of affection 【尺取法 or DP】
//yy:因为这题多组数据,DP预处理存储状态比每次尺取快多了,但是我更喜欢这个尺取的思想. 题目链接:codeforces 814 C. An impassioned circulation of ...
- 【Codeforces Round 418】An impassioned circulation of affection DP
C. An impassioned circulation of affection ...
- An impassioned circulation of affection
An impassioned circulation of affection time limit per test 2 seconds memory limit per test 256 mega ...
- Codeforces Round #418 (Div. 2) C. An impassioned circulation of affection
C. An impassioned circulation of affection time limit per test 2 seconds memory limit per test 256 m ...
- 【尺取或dp】codeforces C. An impassioned circulation of affection
http://codeforces.com/contest/814/problem/C [题意] 给定一个长度为n的字符串s,一共有q个查询,每个查询给出一个数字m和一个字符ch,你的操作是可以改变字 ...
- codeforces 814 C. An impassioned circulation of affection(二分+思维)
题目链接:http://codeforces.com/contest/814/problem/C 题意:给出一串字符串然后q个询问,问替换掉将m个字符替换为字符c,能得到的最长的连续的字符c是多长 题 ...
- C. An impassioned circulation of affection DP
http://codeforces.com/contest/814/problem/C 12ooyomioomioo21 o2 o 这题我是用dp解的,不过好像很慢,比赛的时候算了下不会mle,就没滚 ...
- CF814C An impassioned circulation of affection
思路: 对于题目中的一个查询(m, c),枚举子区间[l, r](0 <= l <= r < n),若该区间满足其中的非c字符个数x不超过m,则可以将其合法转换为一个长度为r-l+1 ...
- Codeforces 814C - An impassioned circulation of affection
原题链接:http://codeforces.com/contest/814/problem/C 题意:有长度为n的一个字符串,q个询问,每个询问由数字m和字符c组成,问最多在字符串中替换m个字符,使 ...
随机推荐
- 《构建之法》第6~7章读后感和对Scrum的理解
第6章 敏捷流程 “敏捷流程”是一系列价值观和方法论的集合.从2001年开始,一些软件界的专家开始倡导“敏捷”的价值观和流程, 他们肯定了流行做法的价值,但是强调敏捷的做法更能带来价值. 敏捷开发原则 ...
- PAT L1 - 056 猜数字
https://pintia.cn/problem-sets/994805046380707840/problems/994805074646122496 一群人坐在一起,每人猜一个 100 以内的数 ...
- Kafka集群无法外网访问问题解决攻略
Kafka无法集群外网访问问题解决方法 讲解本地消费者和生产者无法使用远程Kafka服务器的处理办法 服务搭建好Kafka服务后,机本.测试 OK,外面机器却无法访问,很是怪异. 环境说明: Ka ...
- webgl helloworld
之前的webgl 初识1, 初识2 已经介绍了webgl的基本概念,工作原理. 没有理解的自己yy. 现呈上例子一枚 <!DOCTYPE html> <html lang=" ...
- 使用JMeter代理录制app测试脚本
准备条件:JMeter.手机app 上一篇介绍过录制Web测试脚本的方式有两种,使用代理和使用第三方工具.本篇录制app测试脚本只讨论使用代理的方式,其他方式以后有机会再补充.其实Web和app使用代 ...
- 移动端开发-viewport
1.viewport viewport 即设备 屏幕上显示网页的区域.因为移动设备屏幕比较小,为了能让移动设备能够显示更多内容,默认设置的viewport 并不是屏幕真是像素点的宽度,一般为980px ...
- 关于setInterval()定时
最近项目中,遇到个需求就是获取停车场剩余车位数量,想是通过ajax定时抓取接口数据来实现(本想通过SignalR),但是项目本身直供少数人使用,感觉定时ajax可以满足 下面上代码 var handl ...
- 关于slow http attack以及apche tomcat的应对方式
HTTP 的 Slow Attack 有着悠久历史的 HTTP DOS 攻击方式,最早大约追溯到 5 年前,按理说早该修复了,但是 Apache 的默认配置中仍然没有添加相关配置,或者他们认为这是 f ...
- 【CF484E】Sign on Fence(主席树)
[CF484E]Sign on Fence(主席树) 题面 懒得贴CF了,你们自己都找得到 洛谷 题解 这不就是[TJOI&HEOI 排序]那题的套路吗... 二分一个答案,把大于答案的都变成 ...
- BZOJ3110 K大数查询 【线段树 + 整体二分 或 树套树(非正解)】
Description 有N个位置,M个操作.操作有两种,每次操作如果是1 a b c的形式表示在第a个位置到第b个位置,每个位置加入一个数c 如果是2 a b c形式,表示询问从第a个位置到第b个位 ...