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 ...
随机推荐
- qq浏览器默认字体设置
- 软工网络15团队作业4——Alpha阶段敏捷冲刺8.0
软工网络15团队作业4--Alpha阶段敏捷冲刺8.0 1.每天举行站立式会议,提供当天站立式会议照片一张. 2.项目每个成员的昨天进展.存在问题.今天安排. 2.1 任务完成安排: 成员 昨日已完成 ...
- 在统一软件开发过程中使用UML
如何在统一软件开发过程中使用UML? 起始阶段常用UML图 在起始阶段,通常有用例图.类图.活动图.顺序图等UML图的参与. 获取用户需求之后首先要将这些需求转化为系统的顶层用例图. 在确定了用例之后 ...
- Shader2.0常用语义
POSITION: 获取模型顶点的信息.NORMAL: 获取法线信息TEXCOORD(n): 高精度的从顶点传递信息到片段着色器COLOR: 表示低精度从顶点传递信息到片段着色器 ...
- scu 4439 Vertex Cover
题意: 给出n个点,m条边,将若干个点染色,使得每个边至少有一点染色,问至少染多少个点. 思路: 如果是二分图,那就是最小点覆盖,但是这是一般图. 一般图的最小覆盖是npc问题,但是这题有一个条件比较 ...
- 20155228 2016-2017-2 《Java程序设计》第5周学习总结
20155228 2016-2017-2 <Java程序设计>第5周学习总结 教材学习内容总结 异常处理 try-catch语法:JVM执行try区块中的代码,如果发生错误就会跳到catc ...
- 【Hadoop学习之二】Hadoop伪分布式安装
环境 虚拟机:VMware 10 Linux版本:CentOS-6.5-x86_64 客户端:Xshell4 FTP:Xftp4 jdk8 hadoop-3.1.1 伪分布式就 ...
- Spring boot 入门配置
1,maven 的pom 文件里面引入 <!-- spring boot 父节点依赖,引入这个之后相关的引入就不需要添加version配置,spring boot会自动选择最合适的版本进行添加. ...
- 如何用新安装的jdk替换掉Linux系统默认jdk
版主写的非常棒: http://blog.csdn.net/u011364306/article/details/48375653
- Unity3d 5.x搭载VS2013使用
1. 安装unity vs.首先我们打开我们下载的unity vs.然后就会看见里面有3个文件,我们双击UnityVS 2013-1.8.1.msi.进行安装,在其过程狂点击下一步就可以,直到点击 ...