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) ...
随机推荐
- python3.6安装遇到的问题
Ubuntu16.04版本最新的Python 3.x版本3.5 . 可以从源代码执行安装最新稳定版本3.6. 要安装Python 3.6 ,请运行以下命令: # wget https://www.py ...
- T1191 数轴染色 codevs
http://codevs.cn/problem/1191/ 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Descr ...
- GRYZY- #10. 财富
财富(treasure) Time Limit:1000ms Memory Limit:128MB 题目描述 LYK有n个小伙伴.每个小伙伴有一个身高hi. 这个游戏是这样的,LYK生活的环境是以身高 ...
- 存code
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> us ...
- Centos7 下安装 RabbitMQ
安装 erlang 1.下载erlang 官网地址 http://www.erlang.org/download 挑选合适的版本 然后 wget 比如目前最新版本 19.3 运行命令 wget htt ...
- 【转载】C#中回滚TransactionScope的使用方法和原理
TransactionScope只要一个操作失败,它会自动回滚,Complete表示事务完成 实事上,一个错误的理解就是Complete()方法是提交事务的,这是错误的,事实上,它的作用的表示本事务完 ...
- Beijing Bus
Search: http://bjgj.aibang.com:8899 https://github.com/sp-chenyang/bus https://github.com/leavind/Co ...
- RC4算法的Python实现详注
刚对RC4算法进行了学习,网上发现https://ju.outofmemory.cn/entry/46753 中作者展示了RC4的python实现,但代码缺乏注释,较为晦涩,因此本文对部分代码进行了注 ...
- 利用NSMutableAttributedString实现label上字体大小颜色行间距的改变
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.si ...
- cocoapods导入框架出错 The dependency `FMDB` is not used in any concrete target
问题描述: The dependency `FMDB` is not used in any concrete target 解决办法: 官网是这样给推荐的: 在创建Podfile的时候,用这种格式使 ...