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个字符,使 ...
随机推荐
- 对IT行业的看法和对软件工程的理解
现在社会上IT行业的人才需求越来越大,而作为一个学软件工程的大学生,我认为IT行业是一个前景十分强大的发展方向,而且现在的社会越来越信息化,未来的生活中,电脑肯定是不可缺少的,所以我认为IT行业这是一 ...
- javac和java的使用
java -Xmx128m -Dfile.encoding=gbk -cp ./;bin/;./*;lib/* com.qianlima.crawlOthers.Icp REM REM block e ...
- PreparedStatement的execute误解
boolean execute() throws SQLException在此 PreparedStatement 对象中执行 SQL 语句,该语句可以是任何种类的 SQL 语句.一些特别处理过的语 ...
- libmnl
https://www.netfilter.org/projects/libmnl/doxygen/modules.html 1,tar xvf libmnl-1.0.4.tar.gz 2,cd li ...
- 面试- 阿里-. 大数据题目- 给定a、b两个文件,各存放50亿个url,每个url各占64字节,内存限制是4G,让你找出a、b文件共同的url?
假如每个url大小为10bytes,那么可以估计每个文件的大小为50G×64=320G,远远大于内存限制的4G,所以不可能将其完全加载到内存中处理,可以采用分治的思想来解决. Step1:遍历文件a, ...
- MAC 下用 brew 搭建 PHP 开发环境
Mac下用brew搭建PHP(LNMP/LAMP)开发环境 Mac下搭建lamp开发环境很容易,有xampp和mamp现成的集成环境.但是集成环境对于经常需要自定义一些配置的开发者来说会非常麻烦,而且 ...
- 【Linux笔记】Linux中inittab剖析
Linux完成内核(Kernel)引导后,会由init初始化进程调用/etc/inittab配置文件(ps -aux | less,init进程号为始终为1,是所有系统进程的起点,init进程也有一个 ...
- 第81天:jQuery 插件使用方法
在追求页面互动效果的时代,大家都想把页面效果做的美轮美奂,这一切都离不开前端技术脚本Javascript,而最近常被人用到的Javascript库文件则是jQuery. jQuery的使用具体步骤如 ...
- 【.Net】输出的字符靠右对齐
先看下面的这组字符,如果输出来,它是无法靠右对齐: " }; foreach (string s in s1) { string s2 = s; Console.WriteLine(s2); ...
- Luogu4926 倍杀测量者(二分答案+差分约束)
容易想到二分答案.问题变为判断是否所有条件都被满足,可以发现这是很多变量间的相对关系,取个log之后就是经典的差分约束模型了.特殊的地方在于某些人的分数已被给定,从每个人开始跑一遍最短路判断一下是否能 ...