Problem Description
Little Q is now checking whether string A matches B. Two strings are considered matched if they have the same length, and there are
no position i that Ai is different from Bi.
However, Little Q is a kind man, he forgives every person hurt him. What's more, he even forgives strings! He gives the string 3
opportunities, if there are no more than 3 positions i that Ai is different from Bi, then Little Q will also consider the two strings
matched.
For a string S, S[l,r] means the substring combined by Sl,Sl+,...,Sr. And the function occ(A,B) returns the number of substrings
in string B which matches A.
Little Q now has a long numeric -based string S, and his job is to deal with m operations: . + l r k, for every positions from l to r, change Si to (Si+k)mod10.
. ? l r T, report occ(T,S[l,r]). After lots of work, Little Q is very tired now, please write a program to help him deal with these operations. Input
The first line of the input contains an integer T(≤T≤), denoting the number of test cases.
In each test case, there are two integers n(≤n≤) and m(≤m≤) in the first line, denoting the length of string S and the
number of operations.
The second line of the input contains a numeric string S with n integers, each number Si is in the range of to .
In the following m lines, each line describes an operation.
If it is a modification, then it is in the format of ''+ l r k'', where ≤l≤r≤n and ≤k≤.
If it is a query, then it is in the format of ''? l r T'', where ≤l≤r≤n and T is a numeric string composed of integers from to .
It is guaranteed that ∑|T|≤ in each test case, and there are no more than test cases satisfying min(n,m)>. Output
For each query, print a single line with an integer, denoting the answer. Sample Input ?
?
?
+
? Sample Output

题意:给定字符串S,多次修改区间值,多次询问区间有多少匹配串T,可以失配3次。

超时思路:用bitset的思路去做的,每次记录T的相应位置[0,L-1]的集合,一位一位的移、求并,对于出现的失配位置,我们最多可以更新3次。假设数据小一点,没准可以过。 主要还是修改操作那里太暴力的,单点操作的题是遇到过了。

( :D, 虽然是个超时代码,但是我觉得能想出来这个不算太暴力的方法也算不错啦。以后没准能用上。

#include<bitset>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=;
int s[][maxn],ans[maxn],tans[maxn];
char a[maxn],c[maxn],opt[];
int times[maxn];
int main()
{
int T,N,M,L;
scanf("%d",&T);
while(T--){
scanf("%d%d",&N,&M);
scanf("%s",a+);
int i,j,l,r,k;
for(i=;i<;i++) for(j=;j<=N;j++) s[i][j]=;
for(i=;i<=N;i++) s[a[i]-''][i]=;
while(M--){
scanf("%s",opt);
if(opt[]=='+'){
scanf("%d%d%d",&l,&r,&k);
for(i=l;i<=r;i++){
s[a[i]-''][j]=;
a[i]=char((a[i]-''+k)%+'');
s[a[i]-''][i]=;
}
}
else {
scanf("%d%d%s",&l,&r,c);
L=strlen(c);
if(L>r-l+) {
puts(""); continue;
}
for(i=l;i<=r;i++) times[i]=;
for(i=l;i<=r;i++) ans[i]=;//全部为1
for(i=;i<L;i++){
for(j=l;j<=r;j++) tans[j]=ans[j];
for(j=l;j<=r-L+;j++)
ans[j]&=s[c[i]-''][j+i];
for(j=l;j<=r-L+;j++){
if(!ans[j]&&tans[j]&&times[j]<){
times[j]++; ans[j]=;
}
}
}
int res=;
for(i=l;i<=r-L+;i++) if(ans[i]) res++;
printf("%d\n",res);
}
}
}
return ;
}

HDU6028:Forgiveness(TLE ing,占位)的更多相关文章

  1. .NET 基础 一步步 一幕幕[运算符、占位符、转义符]

      运算符.占位符.转义符 好吧,在五局全胜之后,终于升到了三个钻,距离一个星星还有一大段距离,忽然想起来今天的博客还没写,果断坑队友,来写博客了....感觉以后还是每天更新一篇比较好.要不晚上就该熬 ...

  2. [占位-未完成]scikit-learn一般实例之十一:异构数据源的特征联合

    [占位-未完成]scikit-learn一般实例之十一:异构数据源的特征联合 Datasets can often contain components of that require differe ...

  3. [占位-未完成]scikit-learn一般实例之十:核岭回归和SVR的比较

    [占位-未完成]scikit-learn一般实例之十:核岭回归和SVR的比较

  4. 占位符行为 PlaceHolderBehavior 的实现以及使用

    这个效果我不太会描述 PlaceHolder直译占位符 也有人把这个效果叫水印效果 就是和HTML5的PlaceHolder属性一样的效果 上图直观: 使用方法: 首先下载 占位符行为dll.rar  ...

  5. [Sass]占位符 %placeholder

    [Sass]占位符 %placeholder Sass 中的占位符 %placeholder 功能是一个很强大,很实用的一个功能,这也是我非常喜欢的功能.他可以取代以前 CSS 中的基类造成的代码冗余 ...

  6. html内的空格占位

    写html的时候有时因为字数不够会根据字段长度添加多个空格,但是在html中添加空格是没有用的,所以使用空格的代替符号有:   不断行的空白(1个字符宽度)   半个空白(1个字符宽度)   一个空白 ...

  7. 《Android NFC 开发实战详解 》简介+源码+样章+勘误ING

    <Android NFC 开发实战详解>简介+源码+样章+勘误ING SkySeraph Mar. 14th  2014 Email:skyseraph00@163.com 更多精彩请直接 ...

  8. SPRING多个占位符配置文件解析源码研究--转

    原文地址:http://www.cnphp6.com/archives/85639 Spring配置文件: <context:property-placeholder location=&quo ...

  9. NSLog 占位符

    转自:http://blog.sina.com.cn/s/blog_75f190280101dmj8.html [iOS]Objective-C占位符使用 (2013-10-21 10:24:16) ...

随机推荐

  1. Atcoder 3857 Median Sum

    Problem Statement You are given N integers A1, A2, ..., AN. Consider the sums of all non-empty subse ...

  2. NSURLConnection和NSMutableURLRequest 实现同步、异步请求

    我是走向ios的一个小书童,我有很多不懂的,新鲜的知识去学习,去掌握! 我首先要吐槽一下: 那些不负责的博友!你分享知识本来是好事!可是你直接Control+V就是你的不对了! 尼玛,直接Contro ...

  3. 【转】C语言中整型运算取Ceiling问题

    原文:http://blog.csdn.net/laciqs/article/details/6662472 --------------------------------------------- ...

  4. hdoj-3371-Connect the Cities【最小生成树】

    Connect the Cities Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...

  5. memchached你知道和不知道的事

  6. FastDFS的配置、部署与API使用解读(1)Get Started with FastDFS(转)

    转载请注明来自:诗商·柳惊鸿CSDN博客,原文链接:FastDFS的配置.部署与API使用解读(1)入门使用教程 1.背景 FastDFS是一款开源的.分布式文件系统(Distributed File ...

  7. HashTable源代码剖析

    <span style="font-size:14px;font-weight: normal;">public class Hashtable<K,V> ...

  8. Android学习笔记(十)——使用意图链接活动

    使用意图链接活动 1.新建一个名为"UsingIntent"的项目,右击src目录下的包名,选择New-->Class选项.并将新的类文件名称命名为"SecondA ...

  9. android-custom-tab-with-viewpager

    https://github.com/eltld/android-custom-tab-with-viewpager

  10. RecyclerViewDemo

    https://github.com/eltld/RecyclerViewDemo