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) ...
随机推荐
- spring--路由
@RestController: Spring4之后新加入的注解,原来返回json需要@ResponseBody和@Controller配合. 即@RestController是@ResponseBo ...
- ubuntu下不同版本python安装pip及pip的使用
由于ubuntu系统自带python2.7(默认)和python3.4,所以不需要自己安装python. 可以使用python -V和python3 -V查看已安装python版本. 在不同版本的py ...
- VScode开发Vue初尝试(一)
由于公司近期有新的H5项目开发,而前端的同事也离职了,所以就临时顶缸,研究学习一下Vue框架开发. 本人也是初学,在学习过程中,把一些学习所得分享出来,可能会有很多问题和疏漏,希望大家能够多多指正,共 ...
- android test控件
1.Plain Text 输入文本框 <EditText android:id="@+id/editText" android:layout_width="wrap ...
- pandaboard安装ubuntu14.04系统遇到的问题
按照该网址步骤安装https://www.eewiki.net/display/linuxonarm/PandaBoard 在linux kernel的./build_kernel.sh时,自动安装交 ...
- ios Crash Log 分析汇总
方法一: 1.xcode 有自带的symbolicatecrash,可以将.crash文件中的16进制地址转换成可读的函数地址. symbolicatecrash位于: /Applications/X ...
- UICollectionView 使用 介绍
1.1. Collection View 全家福: UICollectionView, UITableView, NSCollectionView n 不直接等效于NSCollectionView ...
- uiimage缩放图片大小和属性UIViewContentModeScaleAspectFit
UIImageView *tmp = [[UIImageView alloc]initWithFrame:CGRectMake(5.0f, 5.0f, 40.0f, 40.0f)]; ...
- centos安装配置nginx,ssl生产和配置教程
[一]nginx安装nginx安装带ssl扩展: cd /usr/local/src #进入用户目录wget http://nginx.org/download/nginx-1.15.0.tar.gz ...
- 安卓开发懒鬼最爱之ButterKnife,依赖注入第三方是库,进一步加速开发速度
转载请注明出处:王亟亟的大牛之路 还在烦躁一大堆findById的控件操作而烦恼么? 平时,我们的那一系列findById是一个"浩大的project"样比例如以下 这是以前一个项 ...