题目链接: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(尺取+预处理)的更多相关文章

  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. 第六周PSP &进度条

    团队项目PSP 一.表格:     C类型 C内容 S开始时间 E结束时间 I时间间隔 T净时间(mins) 预计花费时间(mins) 讨论 讨论alpha完成情况并总结 9:40 11:20 17 ...

  2. 【php】session读写锁

    事件:a文件中操作$_SESSION['start'] = 'yes'; sleep(100);  休眠100s 在这休眠的时间段中,b文件操作$_SESSION['start'] = 'no'; 结 ...

  3. java 基础 --File

    1, 创建文件 File file = new File(path); file.createNewFile(); //如果路径不存在,会抛异常 file.mkdir();//如果路径不存在,返回fa ...

  4. DHCP:动态主机配置协议

    DHCP(Dynamic Host Configuration Protocol,动态主机配置协议)是一个局域网的网络协议,使用UDP协议工作, 主要有两个用途:给内部网络或网络服务供应商自动分配IP ...

  5. HDU4802_GPA

    水题. #include <iostream> #include <cstdio> #include <cstring> using namespace std; ...

  6. MySQL复制 -- Binlog (1)

    复制之所以工作得益于MySQL把对数据库的变更都记录在 binlog中,然后主库把它读出来,放到从库上去应用.当然binlog 的用途不仅限于此,比如 PITR等 在5.1.4版本以前,binlog格 ...

  7. day4 列表 增删改查 元组

    增lis=["a","b","c",5,7,4]lis.append("s")#在列表的末尾追加lis.extend(& ...

  8. CSS预处理语言-less 的使用

    Less 是一门 CSS 预处理语言,它扩展了 CSS 语言,增加了变量.Mixin.函数等特性,使 CSS 更易维护和扩展. Less 可以运行在 Node 或浏览器端. Less的编译处理 作为一 ...

  9. Django文字教程

    user-----URL对应关系-------视图函数def func1()-------------- 函数给用户返回的实质上就是一个字符串,过程:通过open函数打开HTML,把HTML读到内存中 ...

  10. 【JQuery】文档操作

    一.前言 接着上一章的内容,接着JQuery的学习 二.内容 addClass 向被选元素添加一个或多个类 $(selector).addClass(class) $(selector).addCla ...