题目链接:http://codeforces.com/contest/814/problem/C

题目:

题意:给你一个长度为n的字符串,m次查询,每次查询:最多进行k步修改,求字符c(要输入的字符)最长连续的长度。

思路:尺取法,预处理出每个字符连续长度为k需要的代价,然后O1查询。

代码实现如下:

  1. #include <set>
  2. #include <map>
  3. #include <queue>
  4. #include <stack>
  5. #include <cmath>
  6. #include <bitset>
  7. #include <cstdio>
  8. #include <string>
  9. #include <vector>
  10. #include <cstdlib>
  11. #include <cstring>
  12. #include <iostream>
  13. #include <algorithm>
  14. using namespace std;
  15.  
  16. typedef long long ll;
  17. typedef pair<ll, ll> pll;
  18. typedef pair<ll, int> pli;
  19. typedef pair<int, ll> pil;;
  20. typedef pair<int, int> pii;
  21. typedef unsigned long long ull;
  22.  
  23. #define lson i<<1
  24. #define rson i<<1|1
  25. #define bug printf("*********\n");
  26. #define FIN freopen("D://code//in.txt", "r", stdin);
  27. #define debug(x) cout<<"["<<x<<"]" <<endl;
  28. #define IO ios::sync_with_stdio(false),cin.tie(0);
  29.  
  30. const double eps = 1e-;
  31. const int mod = ;
  32. const int maxn = + ;
  33. const double pi = acos(-);
  34. const int inf = 0x3f3f3f3f;
  35. const ll INF = 0x3f3f3f3f3f3f3f;
  36.  
  37. int n, q, x, cnt;
  38. char s[maxn], c[];
  39. int ans[][maxn];
  40.  
  41. int main() {
  42. //FIN;
  43. scanf("%d%s", &n, s);
  44. for(int i = ; i < ; i++) {
  45. for(int j = ; j < n; j++) {
  46. cnt = ;
  47. for(int k = j; k < n; k++) {
  48. if(s[k] != 'a' + i) cnt++;
  49. ans[i][cnt] = max(ans[i][cnt], k - j + );
  50. }
  51. }
  52. for(int j = ; j <= n; j++) {
  53. ans[i][j] = max(ans[i][j], ans[i][j-]);
  54. }
  55. }
  56. scanf("%d", &q);
  57. while(q--) {
  58. scanf("%d%s", &x, c);
  59. int num = c[] - 'a';
  60. printf("%d\n", ans[num][x]);
  61. }
  62. return ;
  63. }

An impassioned circulation of affection(尺取+预处理)的更多相关文章

  1. codeforces 814 C. An impassioned circulation of affection 【尺取法 or DP】

    //yy:因为这题多组数据,DP预处理存储状态比每次尺取快多了,但是我更喜欢这个尺取的思想. 题目链接:codeforces 814 C. An impassioned circulation of ...

  2. 【Codeforces Round 418】An impassioned circulation of affection DP

                                                            C. An impassioned circulation of affection   ...

  3. An impassioned circulation of affection

    An impassioned circulation of affection time limit per test 2 seconds memory limit per test 256 mega ...

  4. 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 ...

  5. 【尺取或dp】codeforces C. An impassioned circulation of affection

    http://codeforces.com/contest/814/problem/C [题意] 给定一个长度为n的字符串s,一共有q个查询,每个查询给出一个数字m和一个字符ch,你的操作是可以改变字 ...

  6. codeforces 814 C. An impassioned circulation of affection(二分+思维)

    题目链接:http://codeforces.com/contest/814/problem/C 题意:给出一串字符串然后q个询问,问替换掉将m个字符替换为字符c,能得到的最长的连续的字符c是多长 题 ...

  7. C. An impassioned circulation of affection DP

    http://codeforces.com/contest/814/problem/C 12ooyomioomioo21 o2 o 这题我是用dp解的,不过好像很慢,比赛的时候算了下不会mle,就没滚 ...

  8. CF814C An impassioned circulation of affection

    思路: 对于题目中的一个查询(m, c),枚举子区间[l, r](0 <= l <= r < n),若该区间满足其中的非c字符个数x不超过m,则可以将其合法转换为一个长度为r-l+1 ...

  9. Codeforces 814C - An impassioned circulation of affection

    原题链接:http://codeforces.com/contest/814/problem/C 题意:有长度为n的一个字符串,q个询问,每个询问由数字m和字符c组成,问最多在字符串中替换m个字符,使 ...

随机推荐

  1. 对IT行业的看法和对软件工程的理解

    现在社会上IT行业的人才需求越来越大,而作为一个学软件工程的大学生,我认为IT行业是一个前景十分强大的发展方向,而且现在的社会越来越信息化,未来的生活中,电脑肯定是不可缺少的,所以我认为IT行业这是一 ...

  2. javac和java的使用

    java -Xmx128m -Dfile.encoding=gbk -cp ./;bin/;./*;lib/* com.qianlima.crawlOthers.Icp REM REM block e ...

  3. PreparedStatement的execute误解

    boolean execute()  throws SQLException在此 PreparedStatement 对象中执行 SQL 语句,该语句可以是任何种类的 SQL 语句.一些特别处理过的语 ...

  4. libmnl

    https://www.netfilter.org/projects/libmnl/doxygen/modules.html 1,tar xvf libmnl-1.0.4.tar.gz 2,cd li ...

  5. 面试- 阿里-. 大数据题目- 给定a、b两个文件,各存放50亿个url,每个url各占64字节,内存限制是4G,让你找出a、b文件共同的url?

    假如每个url大小为10bytes,那么可以估计每个文件的大小为50G×64=320G,远远大于内存限制的4G,所以不可能将其完全加载到内存中处理,可以采用分治的思想来解决. Step1:遍历文件a, ...

  6. MAC 下用 brew 搭建 PHP 开发环境

    Mac下用brew搭建PHP(LNMP/LAMP)开发环境 Mac下搭建lamp开发环境很容易,有xampp和mamp现成的集成环境.但是集成环境对于经常需要自定义一些配置的开发者来说会非常麻烦,而且 ...

  7. 【Linux笔记】Linux中inittab剖析

    Linux完成内核(Kernel)引导后,会由init初始化进程调用/etc/inittab配置文件(ps -aux | less,init进程号为始终为1,是所有系统进程的起点,init进程也有一个 ...

  8. 第81天:jQuery 插件使用方法

    在追求页面互动效果的时代,大家都想把页面效果做的美轮美奂,这一切都离不开前端技术脚本Javascript,而最近常被人用到的Javascript库文件则是jQuery.  jQuery的使用具体步骤如 ...

  9. 【.Net】输出的字符靠右对齐

    先看下面的这组字符,如果输出来,它是无法靠右对齐: " }; foreach (string s in s1) { string s2 = s; Console.WriteLine(s2); ...

  10. Luogu4926 倍杀测量者(二分答案+差分约束)

    容易想到二分答案.问题变为判断是否所有条件都被满足,可以发现这是很多变量间的相对关系,取个log之后就是经典的差分约束模型了.特殊的地方在于某些人的分数已被给定,从每个人开始跑一遍最短路判断一下是否能 ...