Codeforces Round #418 (Div. 2) C. An impassioned circulation of affection(尺取)
来源:互联网 发布:python经典视频教程 编辑:程序博客网 时间:2024/06/11 15:13
题意:给你一个长度为n的字符串,q次询问m ch,每次问可最多改变m个字符,问最多连续多少个ch。
n <= 1000, q <= 200000.
思路:尺取法预处理记录出每个字母,改变m次能大连续长度。
代码:
#include<bits/stdc++.h>using namespace std;typedef long long ll;const int maxn = 1505;char str[maxn];int n, dp[30][maxn], sum[30][maxn];void solve(){ for(int i = 0; i < 26; i++) { for(int j = 0; j <= n; j++) { int l = 1, r = 1; int tmp = 0; while(r <= n) { while(r-l+1 - (sum[i][r]-sum[i][l-1]) <= j) r++; tmp = max(tmp, r-l); l++; } dp[i][j] = tmp; } }}int main(void){ while(cin >> n) { memset(sum, 0, sizeof(sum)); memset(dp, 0, sizeof(dp)); for(int i = 1; i <= n; i++) { scanf(" %c", &str[i]); for(int j = 0; j < 26; j++) sum[j][i] = sum[j][i-1]; sum[str[i]-'a'][i]++; } solve(); int q; scanf("%d", &q); while(q--) { int c; char ch; scanf("%d %c", &c, &ch); printf("%d\n", dp[ch-'a'][c]); } } return 0;}
阅读全文
2 0
- Codeforces Round #418 (Div. 2) C. An impassioned circulation of affection(尺取)
- Codeforces Round #418 (Div. 2) -- C. An impassioned circulation of affection(DP预处理)
- Codeforces Round #418 (Div. 2) 814 C. An impassioned circulation of affection
- Codeforces Round #418 (Div. 2) C. An impassioned circulation of affection
- Codeforces Round #418 (Div. 2)C.An impassioned circulation of affection(暴力枚举)
- Codeforces Round #418 (Div. 2) C. An impassioned circulation of affection
- Codeforces Round #418 (Div. 2) C. An impassioned circulation of affection 预处理
- CF-Codeforces Round #418 (Div. 2)-C-An impassioned circulation of affection
- Codeforces Round #418 C--An impassioned circulation of affection
- codeforces 418div2 C. An impassioned circulation of affection(尺取)
- CF Round #418( Div.2) An impassioned circulation of affection
- codeforces C. An impassioned circulation of affection
- Codeforces#418 An impassioned circulation of affection
- Codeforces#418C An impassioned circulation of affection
- 【Codeforces 814 C. An impassioned circulation of affection】+ 尺取法
- codeforces 814 C. An impassioned circulation of affection(暴力)
- Codeforces-An impassioned circulation of affection (尺取法)
- codeforces 814C An impassioned circulation of affection(尺取法模板)
- Map和AbstractMap
- opencv访问图像像素及简单应用
- JAVA从基础到精通(包装类)
- [bzoj3130][Sdoi2013]费用流 二分+最大流
- progressBar(进度条)
- Codeforces Round #418 (Div. 2) C. An impassioned circulation of affection(尺取)
- 【Python】9“切片和迭代“
- 前端问题总结
- 进度条UIProgressView和计步器结合
- 大数据-十
- Spring4第三讲学习笔记,依赖注入dependency injection
- 读取手机联系人
- 20170607Windows09_04_进程复习
- PAT--1040. Longest Symmetric String