题意:找出字符串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 + 10;
const ull seed = 131;
ull bin[maxn], Hash[maxn];
char p[maxn], w[maxn], ans[maxn];
void init(){bin[0] = 1;for(int i = 1; i < maxn; i++)bin[i] = bin[i - 1] * seed;
}
int main(){init();while(~scanf("%s%s", w + 1, p + 1)){int lenw = strlen(w + 1), len = strlen(p + 1);ull aim = 0;if(lenw > len){printf("%s\n", p + 1);}else{int point = 1;for(int i = 1; i <= lenw; i++)aim = aim * seed + w[i] - 'a';Hash[0] = 0;for(int i = 1; i <= lenw - 1; i++){Hash[point] = Hash[point - 1] * seed + p[i] - 'a';ans[point++] = p[i];}for(int i = lenw; i <= len; i++){Hash[point] = Hash[point - 1] * 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 = 1; i < point; i++){printf("%c", ans[i]);}printf("\n");}}return 0;
}

转载于:https://www.cnblogs.com/KirinSB/p/9895757.html

SCU 4438 Censor(Hash)题解相关推荐

  1. 【哈希-字符串匹配+模拟栈】SCU - 4438: Censor(哈希详解哈哈哈)

    写在前:由于哈希没有好好听讲,也没有下来看.这是排位我开的第一道题,直接string暴力T了.昨天其实就看了哈希,太浮躁,于是本来很简单的哈希愣是没看懂.(于是放弃去看爱5了23333333)今天补上 ...

  2. ACM: SCU 4438 Censor - KMP

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

  3. SCU 4438 Censor 字符串hash

    http://fastvj.rainng.com/problem/SCU-4438 题意:一个文本串和模式串,如果文本串中出现了模式串直接删除,然后拼接成一个新串,继续删除.求最后处理过的字符串. 做 ...

  4. SCU - 4438——Censor(哈希)

    题目链接:http://acm.scu.edu.cn/soj/problem.action?id=4438 题意:给出一个串a和串b,串b中如果有a串则删除,删除后b剩下的串再连到一起,再找串a,反复 ...

  5. SCU - 4438 Censor

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

  6. SCU - 4438 Censor (KMP)

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

  7. SCU - 4438 Censor

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

  8. SCU 4438:Censor

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

  9. SCU 4438 Censor

    $KMP$,链表. 将$p$弄成链表,每次匹配到,删掉中间的,继续匹配. #include<bits/stdc++.h> using namespace std;const int INF ...

最新文章

  1. 欢迎来到“现实”世界,bilibili!
  2. 她说:我希望你好好写代码
  3. 交际过程的两个基本环节_跨文化交际学概论笔记(二)
  4. 数据分析用这样的可视化报表,秒杀Excel,再也不怕被说low
  5. 苹果知名开发者怒“怼”:GitHub 不可信,俄罗斯开发者贡献的项目遭毁灭性打击...
  6. dojo省份地市级联之省份Dao接口类(三)
  7. ctf镜子里面的世界_在秋天遇见“冰雪世界”,好像老天给我变了个魔法
  8. python时域转频域_语音预处理(二):时域转频域
  9. IDEA如何新建一个source folder
  10. 软件版本中的Alpha,Beta,RC,Trial是什么意思?
  11. 目标检测---教你利用yolov5训练自己的目标检测模型
  12. APP、网站等注册、登录、改密等发送验证码短信的接入流程---创蓝253云通讯
  13. leaflet实现风场流动
  14. Win10 0x80190001错误解决
  15. while、do...while、for循环的使用
  16. 微信云开发Al短视频一键换脸小程序源码
  17. 【mycat】mycat水平分表
  18. amazon linux虚拟主机,如何在Amazon AWS上设置Linux服务器
  19. Transformer综述大全(2)【A Survey of Visual Transformers】
  20. 台湾厂商未来三个月全面上调主板价格

热门文章

  1. Java中的sleep与wait区别
  2. Nor Flash 编程
  3. mysql表名能大写么_MySQL中表名大小写问题
  4. 前端机器学习--识别人脸在脸颊上画草莓
  5. 工作伦理和消费美学的陷阱
  6. altium designer电气符号和包的常用元素
  7. 三种yum的搭建方法
  8. vscode设置全英文的方法
  9. 某公司程序员薪资一万,而“程序员鼓励师”月薪两万,网友评论炸锅了...
  10. Python数据分析与挖掘——回归模型的诊断