Codeforces Round #418 (Div. 2) C. An impassioned circulation of affection(尺取)
2017-06-07 22:43
453 查看
题意:给你一个长度为n的字符串,q次询问m ch,每次问可最多改变m个字符,问最多连续多少个ch。
n <= 1000, q <= 200000.
思路:尺取法预处理记录出每个字母,改变m次能大连续长度。
代码:
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; }
相关文章推荐
- 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 (Div. 2)C.An impassioned circulation of affection(暴力枚举)
- coderforces--418 div2 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) 814 C. An impassioned circulation of affection
- (dp)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(DP预处理)
- Codeforces-An impassioned circulation of affection (尺取法)
- codeforces 814 C An impassioned circulation of affection
- 【尺取或dp】codeforces C. An impassioned circulation of affection
- 尺取法--An impassioned circulation of affection
- An impassioned circulation of affection
- An impassioned circulation of affection CodeForces - 814C
- Codeforces 814C-An impassioned circulation of affection
- codeforces C. An impassioned circulation of affection
- Codeforces-An impassioned circulation of affection (动态规划/尺取法)
- Codeforces Round #418 (Div. 2) C - An impassioned circulation of(尺取法)