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) ... 
随机推荐
- android本地存储SharedPreferences
			SharedPreferences是Android中最容易理解的数据存储技术,实际上SharedPreferences处理的就是一个key-value(键值对)SharedPreferences常用来 ... 
- 在Oracle Linux上安装dtrace
			http://www.ohsdba.cn/index.php?g=Home&m=Article&a=show&id=171 时间: 2016-10-09 00:40:04 ... 
- 关于ios异步加载图片的几个开源项目
			一.HjCache 原文:http://www.markj.net/hjcache-iphone-image-cache/ 获取 HJCache: HJCache is up on github h ... 
- android  EditText禁止复制粘贴完整代码
			<!-- 定义基础布局LinearLayout --> <LinearLayout xmlns:android="http://schemas.android.com/ap ... 
- 转:libev和libevent的设计差异
			转:http://www.cnblogs.com/Lifehacker/p/whats_the_difference_between_libevent_and_libev_chinese.html [ ... 
- [Testing] Static Analysis Testing JavaScript Applications
			The static code analysis and linting tool ESLint is the de-facto standard for linting JavaScript pro ... 
- SQL经常使用语法
			一.基础 1.创建数据库 CREATE DATABASE database-name 2.删除数据库 drop database dbname 3.备份sql server --- 创建 备份数据的 ... 
- Solidworks做镜像 导致厚度为零的几何体怎么办
			如下图所示,我想把1,2,3,4架子做一个镜像,但是提示错误 貌似只能用镜像实体,并且取消勾选"合并实体" 
- poj 2828 Buy Tickets 【线段树点更新】
			题目:id=2828" target="_blank">poj 2828 Buy Tickets 题意:有n个人排队,每一个人有一个价值和要插的位置,然后当要插的位 ... 
- thinkphp Class 'PDO' not found 错误
			thinkphp Class 'PDO' not found 错误,原因mysql5.7.26缺少pdo驱动,需要安装php的pdo和pdo_mysql扩展 本文以centOS为例 1.进入PHP源码 ... 
