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 + 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)题解相关推荐
- 【哈希-字符串匹配+模拟栈】SCU - 4438: Censor(哈希详解哈哈哈)
写在前:由于哈希没有好好听讲,也没有下来看.这是排位我开的第一道题,直接string暴力T了.昨天其实就看了哈希,太浮躁,于是本来很简单的哈希愣是没看懂.(于是放弃去看爱5了23333333)今天补上 ...
- ACM: SCU 4438 Censor - KMP
SCU 4438 Censor Time Limit:0MS Memory Limit:0KB 64bit IO Format:%lld & %llu Practice Des ...
- SCU 4438 Censor 字符串hash
http://fastvj.rainng.com/problem/SCU-4438 题意:一个文本串和模式串,如果文本串中出现了模式串直接删除,然后拼接成一个新串,继续删除.求最后处理过的字符串. 做 ...
- SCU - 4438——Censor(哈希)
题目链接:http://acm.scu.edu.cn/soj/problem.action?id=4438 题意:给出一个串a和串b,串b中如果有a串则删除,删除后b剩下的串再连到一起,再找串a,反复 ...
- SCU - 4438 Censor
Censor frog is now a editor to censor so-called sensitive words (敏感词). She has a long text pp. Her j ...
- SCU - 4438 Censor (KMP)
Censor frog is now a editor to censor so-called sensitive words (敏感词). She has a long text pp. Her j ...
- SCU - 4438 Censor
Censor frog is now a editor to censor so-called sensitive words (敏感词). She has a long text p . Her j ...
- SCU 4438:Censor
Censor frog is now a editor to censor so-called sensitive words (敏感词). She has a long text p . Her j ...
- SCU 4438 Censor
$KMP$,链表. 将$p$弄成链表,每次匹配到,删掉中间的,继续匹配. #include<bits/stdc++.h> using namespace std;const int INF ...
最新文章
- 欢迎来到“现实”世界,bilibili!
- 她说:我希望你好好写代码
- 交际过程的两个基本环节_跨文化交际学概论笔记(二)
- 数据分析用这样的可视化报表,秒杀Excel,再也不怕被说low
- 苹果知名开发者怒“怼”:GitHub 不可信,俄罗斯开发者贡献的项目遭毁灭性打击...
- dojo省份地市级联之省份Dao接口类(三)
- ctf镜子里面的世界_在秋天遇见“冰雪世界”,好像老天给我变了个魔法
- python时域转频域_语音预处理(二):时域转频域
- IDEA如何新建一个source folder
- 软件版本中的Alpha,Beta,RC,Trial是什么意思?
- 目标检测---教你利用yolov5训练自己的目标检测模型
- APP、网站等注册、登录、改密等发送验证码短信的接入流程---创蓝253云通讯
- leaflet实现风场流动
- Win10 0x80190001错误解决
- while、do...while、for循环的使用
- 微信云开发Al短视频一键换脸小程序源码
- 【mycat】mycat水平分表
- amazon linux虚拟主机,如何在Amazon AWS上设置Linux服务器
- Transformer综述大全(2)【A Survey of Visual Transformers】
- 台湾厂商未来三个月全面上调主板价格