HDU6028:Forgiveness(TLE ing,占位)
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]&×[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,占位)的更多相关文章
- .NET 基础 一步步 一幕幕[运算符、占位符、转义符]
运算符.占位符.转义符 好吧,在五局全胜之后,终于升到了三个钻,距离一个星星还有一大段距离,忽然想起来今天的博客还没写,果断坑队友,来写博客了....感觉以后还是每天更新一篇比较好.要不晚上就该熬 ...
- [占位-未完成]scikit-learn一般实例之十一:异构数据源的特征联合
[占位-未完成]scikit-learn一般实例之十一:异构数据源的特征联合 Datasets can often contain components of that require differe ...
- [占位-未完成]scikit-learn一般实例之十:核岭回归和SVR的比较
[占位-未完成]scikit-learn一般实例之十:核岭回归和SVR的比较
- 占位符行为 PlaceHolderBehavior 的实现以及使用
这个效果我不太会描述 PlaceHolder直译占位符 也有人把这个效果叫水印效果 就是和HTML5的PlaceHolder属性一样的效果 上图直观: 使用方法: 首先下载 占位符行为dll.rar ...
- [Sass]占位符 %placeholder
[Sass]占位符 %placeholder Sass 中的占位符 %placeholder 功能是一个很强大,很实用的一个功能,这也是我非常喜欢的功能.他可以取代以前 CSS 中的基类造成的代码冗余 ...
- html内的空格占位
写html的时候有时因为字数不够会根据字段长度添加多个空格,但是在html中添加空格是没有用的,所以使用空格的代替符号有: 不断行的空白(1个字符宽度) 半个空白(1个字符宽度) 一个空白 ...
- 《Android NFC 开发实战详解 》简介+源码+样章+勘误ING
<Android NFC 开发实战详解>简介+源码+样章+勘误ING SkySeraph Mar. 14th 2014 Email:skyseraph00@163.com 更多精彩请直接 ...
- SPRING多个占位符配置文件解析源码研究--转
原文地址:http://www.cnphp6.com/archives/85639 Spring配置文件: <context:property-placeholder location=&quo ...
- NSLog 占位符
转自:http://blog.sina.com.cn/s/blog_75f190280101dmj8.html [iOS]Objective-C占位符使用 (2013-10-21 10:24:16) ...
随机推荐
- golang log日志
写入日志文件 func main() { file, err := os.Create("test.log") if err != nil { log.Fatalln(" ...
- 在 Windows 下用 TDM-GCC(MinGW)开发 DLL 涉及到数据同步锁及 DLL 初始化终止化函数的问题
在 Windows 下用 TDM-GCC(MinGW)开发 DLL 如果要用到数据同步锁,理论上可以采用 Windows API 提供的临界区实现(需要用到的函数有 InitializeCritica ...
- HDu1241 DFS搜索
#include<iostream> #include<cstring> using namespace std; int a[105][105]; int d[8][2]={ ...
- R读数据stringsAsFactors=F,存数据时row.names = F
stringsAsFactors=F 以前在r里读数据,经常把character读成factor,还得费半天劲把它转回来,尤其是把factor转成numeric还没有那么直接.例如: dat< ...
- (48)C#网络4 web
WebClient 类 提供用于将数据发送到和接收来自通过 URI 确认的资源数据的常用方法 private delegate string delegatehWeb(); private void ...
- Iass、Pass、SasS三种云服务区别?
Iass.Pass.SasS三种云服务区别 我们可以把云计算理解成一栋大楼,而这栋楼又可以分为顶楼.中间.低层三大块.那么我们就可以把Iass(基础设施).Pass(平台).Sass(软件)理解成这栋 ...
- Codeforces 123 E Maze
Discription A maze is represented by a tree (an undirected graph, where exactly one way exists betwe ...
- java多线程02-----------------synchronized底层实现及JVM对synchronized的优化
java多线程02-----------------synchronized底层实现及JVM对synchronized的优化 提到java多线程,我们首先想到的就是synchronized关键字,它在 ...
- Java中常量定义在interface和class的区别(转)
最终结论:定义常量在interface和class中其实都行,关键是看你的设计和个人爱好. Java中interface中定义变量默认都是"public static final" ...
- 10.Java web—JavaBean
定义一个类,然后在jsp页面通过<jsp:useBean>标签调用 重点是类属性名要起得规则,一般是setXXX getXXXX 新建一个类UserInfo public class U ...