题意:找出字符串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. Python 5 -- 模块

    模块 - 模块就是包含函数的文件,用于共享代码. 导入已有模块 # 导入整个模块 import random # 导入整个模块 print(random.randint(0,255)) #调用模块中的 ...

  2. 转:【专题九】实现类似QQ的即时通信程序

    引言: 前面专题中介绍了UDP.TCP和P2P编程,并且通过一些小的示例来让大家更好的理解它们的工作原理以及怎样.Net类库去实现它们的.为了让大家更好的理解我们平常中常见的软件QQ的工作原理,所以在 ...

  3. winscp中使用sudo的方法

    用截图了解如何在 WinSCP 中使用 sudo. 首先你需要检查你尝试使用 WinSCP 连接的 sftp 服务器的二进制文件的位置.你可以使用以下命令检查 SFTP 服务器二进制文件位置: [ro ...

  4. 计算概论(A)/基础编程练习(数据成分)/2:奥运奖牌计数

    #include<stdio.h> int main() { // n天的决赛项目 int n; scanf("%d",&n); ] = {}; while ( ...

  5. git学习总结 - 纯命令

    全局安装git: npm intall git -g 查看git版本: git --version 进入目录,初始化git: 若在目录中使用上一个,不在目录中使用下一个. //已有目录: git in ...

  6. apache编译安装php后需要注意以下配置

    安装后, 编辑apache配置文件 vi /usr/local/apache2/conf/httpd.conf 可以看到 LoadModule php7_module modules/libphp7. ...

  7. Navicat使用ssh连接数据库

    1.主机名或ip地址必须填localhost 2.主机名或ip地址必须填外网ip地址

  8. win10常见问题处理办法

    1.当笔记本连接wifi时,提示,无internet,安全,而手机能正常连接wifi时: cmd(需管理员权限)执行命令 netsh winsock reset 出现已重置,重启电脑 解决方法 2.当 ...

  9. P3317 [SDOI2014]重建(Matrix-tree+期望)

    P3317 [SDOI2014]重建 详情看这位神犇的blog 剩下的注释在code里吧....... #include<iostream> #include<cstdio> ...

  10. k8s渐进

    基本命令介绍(推荐) 1.  The Almighty Pause Container 2. What are Kubernetes Pods Anyway? 3.中文版官方翻译[版本2] 提供了很多 ...