SCU 4438 Censor(Hash)题解
题意:找出字符串p中的w串删除,反复操作,直到找不到w,输出这个串
思路:哈希处理前缀和,如果值相同就删掉。
代码:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<string.h>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<vector>
using namespace std;
typedef unsigned long long ull;
const int maxn = 5e6 + ;
const ull seed = ;
ull bin[maxn], Hash[maxn];
char p[maxn], w[maxn], ans[maxn];
void init(){
bin[] = ;
for(int i = ; i < maxn; i++)
bin[i] = bin[i - ] * seed;
}
int main(){
init();
while(~scanf("%s%s", w + , p + )){
int lenw = strlen(w + ), len = strlen(p + );
ull aim = ;
if(lenw > len){
printf("%s\n", p + );
}
else{
int point = ;
for(int i = ; i <= lenw; i++)
aim = aim * seed + w[i] - 'a';
Hash[] = ;
for(int i = ; i <= lenw - ; i++){
Hash[point] = Hash[point - ] * seed + p[i] - 'a';
ans[point++] = p[i];
}
for(int i = lenw; i <= len; i++){
Hash[point] = Hash[point - ] * seed + p[i] - 'a';
ans[point] = p[i];
if(point >= lenw && Hash[point] - Hash[point - lenw] * bin[lenw] == aim){
point -= lenw;
}
point++;
}
for(int i = ; i < point; i++){
printf("%c", ans[i]);
}
printf("\n");
}
}
return ;
}
SCU 4438 Censor(Hash)题解的更多相关文章
- ACM: SCU 4438 Censor - KMP
SCU 4438 Censor Time Limit:0MS Memory Limit:0KB 64bit IO Format:%lld & %llu Practice D ...
- SCU 4438 Censor(哈希+模拟栈)
Censor frog is now a editor to censor so-called sensitive words (敏感词). She has a long text \(p\). He ...
- SCU 4438 Censor KMP/Hash
题意:给定一个模式串和文本,要求删除所有模式串.可能删除后会形成新的模式串,必须全部删除. 思路1:kmp算法求得失配数组,用一个match数组记录文本串中第i字符和未删除的字符能匹配模式串的长度.这 ...
- SCU 4438 Censor|KMP变形题
传送门 Censor frog is now a editor to censor so-called sensitive words (敏感词). She has a long text P. He ...
- SCU 4438:Censor
Censor frog is now a editor to censor so-called sensitive words (敏感词). She has a long text p . Her j ...
- Censor SCU - 4438
frog is now a editor to censor so-called sensitive words (敏感词). She has a long text (p). Her job is ...
- 四川省赛 SCU - 4438
Censor frog is now a editor to censor so-called sensitive words (敏感词). She has a long text pp. Her j ...
- Hash Killer I II
题意大概: 1.字符串hash不取模,自动溢出 构造数据卡这种hash 2.字符串hash取模1000000007,构造数据卡这种hash 题解传送门:VFleaKing http://vfleak ...
- HGOI20180815 (NOIP 提高组模拟赛 day2)
Day 2 rank 11 100+35+30=165 本题是一道数论题,求ax+by=c的正整数对(x,y) x>=0并且y>=0 先说下gcd: 求a,b公约数gcd(a,b) 如gc ...
随机推荐
- C++中overload(重载),override(覆盖),overwrite(重写/覆写)的区别
#include <cstdio> #include <cstdlib> class Base { public: #pragma region MyRegion1 //函数重 ...
- linux正则
正则表达式 分两类: 基本正则表达式:BRE 扩展正则表达式:ERE :grep -E, egrep 正则表达式引擎: 采用不同算法,检查处理正则表达式的软件模块 PCRE(Perl ...
- sql server得到某个数据库的所有表和所有字段
select b.name tablename,a.name as columnnamefrom sys.columns a,sys.objects b,sys.types cwhere a.obje ...
- 岭回归、LASSO与LAR的几何意义
https://blog.csdn.net/u013524655/article/details/40922303 http://f.dataguru.cn/thread-598486-1-1.htm ...
- vs实现数据库数据迁移
public ActionResult About() { List<ChangeData.Models.old.adsinfo> adsinfo_new = new List<Mo ...
- 转:CTE(公共表表达式)——WITH子句
来自:<Microsoft SQL Server 2008技术内幕:T-SQL语言基础> 一.公共表表达式(CTE,Common Table Expression)是在SQL Server ...
- Ajax 知识
Ajax 为什么要有ajax技术? 传统的web应用,一个简单的操作就要加载整个页面.浪费资源. Ajax 即“Asynchronous Javascript And XML”(异步JavaS ...
- GUI常用对象介绍2
%示意line对象的用法 hf=figure; hl=plot([:]); %示意line对象的属性 get(hl) %设置line的颜色 set(hl,'Color','r'); %设置每个点形状 ...
- 源码下载:74个Android开发开源项目汇总
1. ActionBarSherlock ActionBarSherlock应该算得上是GitHub上最火的Android开源项目了,它是一个独立的库,通过一个API和主题,开发者就可以很方便地使用所 ...
- python02
# 字符串学习第二天 # 1.练习len与range for的使用 test=input("请输入") l=len(test) for i in range(0,l): print ...