题意:找出字符串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)题解的更多相关文章

  1. ACM: SCU 4438 Censor - KMP

     SCU 4438 Censor Time Limit:0MS     Memory Limit:0KB     64bit IO Format:%lld & %llu  Practice D ...

  2. SCU 4438 Censor(哈希+模拟栈)

    Censor frog is now a editor to censor so-called sensitive words (敏感词). She has a long text \(p\). He ...

  3. SCU 4438 Censor KMP/Hash

    题意:给定一个模式串和文本,要求删除所有模式串.可能删除后会形成新的模式串,必须全部删除. 思路1:kmp算法求得失配数组,用一个match数组记录文本串中第i字符和未删除的字符能匹配模式串的长度.这 ...

  4. SCU 4438 Censor|KMP变形题

    传送门 Censor frog is now a editor to censor so-called sensitive words (敏感词). She has a long text P. He ...

  5. SCU 4438:Censor

    Censor frog is now a editor to censor so-called sensitive words (敏感词). She has a long text p . Her j ...

  6. Censor SCU - 4438

    frog is now a editor to censor so-called sensitive words (敏感词). She has a long text (p). Her job is ...

  7. 四川省赛 SCU - 4438

    Censor frog is now a editor to censor so-called sensitive words (敏感词). She has a long text pp. Her j ...

  8. Hash Killer I II

    题意大概: 1.字符串hash不取模,自动溢出  构造数据卡这种hash 2.字符串hash取模1000000007,构造数据卡这种hash 题解传送门:VFleaKing http://vfleak ...

  9. 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 ...

随机推荐

  1. net npoi将List<实体>导出excel的最简单方法

    只是临时导数据用的.方便.最基本的方法, [HttpGet] [Route("ExportEnterprise")] public BaseResponse ExportEnter ...

  2. .net 缓存

    缓存有很多实现方法,所有这些可以被分为两类,基于内存的缓存和基于磁盘的缓存: 1.  内存驻留缓存——包含在内存中临时存储数据的所有实现方法,通常在以下情况下使用: a)       应用程序频繁使用 ...

  3. Redis入门——安装与基本命令

    1. Redis安装 下载地址:https://github.com/MSOpenTech/redis/releases 下载zip文件后直接解压 2. 启动Redis服务端 解压目录下执行redis ...

  4. Spring源码阅读(四)

    我们知道,在spring bean生命周期中,我们可以在不同阶段执行处理器或者方法,比如init-method,destroy方法,BeanPostProcessor接口等.那么这些处理器或方法的执行 ...

  5. Linux基础命令---文本编辑tee

    tee 将标准输入的内容复制到指定的文件中,同时在标准输出中显示. 此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.SUSE.openSUSE.Fedora.   1.语法   ...

  6. 2017年3月29日 webService入门理解 二

    前边说到了N多webService的概念. 其实,说白了,我个人理解的话,webService就是一个“概念”.就好像互联网一样,就是一个很虚幻,很高的一个概念.同样,webService也是.互联网 ...

  7. webpack系统配置

    简言之,webpack 是一个模块打包器 (module bundler),能够将任何资源如 JavaScript 文件.CSS 文件.图片等打包成一个或少数文件. 为什么要用Webpack? 首先, ...

  8. Numpy 通用函数

    frompyfunc的调用格式为frompyfunc(func, nin, nout),其中func是计算单个元素的函数,nin是此函数的输入参数的个数,nout是此函数的返回值的个数 # 注:用fr ...

  9. Installing Android Studio

    To set up Android Studio on Windows: Launch the .exe file you just downloaded. Follow the setup wiza ...

  10. Linux下输出 excel文件

    Linux下输出 excel文件 今日提供给产品需求,需excel文件,故总结要点如下: 1.默认间隔是space_20 2.修改为TAB \t _09 awk '  BEGIN { OFS=&quo ...