有一个S串和一个T串,长度均小于1,000,000,设当前串为U串,然后从前往后枚举S串一个字符一个字符往U串里添加,若U串后缀为T,则去掉这个后缀继续流程。
将s中的每一个字符压入栈
暴力将s中的字符和t中的一个一个匹配,若能够匹配
若不能匹配,我们利用next数组转移匹配的位置
同时我们利用另一个栈来存储匹配到的位置,这意味着我们的两个栈时同时进栈同时出栈的
当我们匹配到的长度为t的长度时,我们将栈中的"t"出栈
如此进行
最后输出栈中剩余字符
口胡有点说不清,建议看代码

 #include<bits/stdc++.h>
using namespace std;
const int maxn = ;
char s[maxn], t[maxn];
int Next[maxn];
int s2[maxn], top = ;
char s1[maxn];
int lens, lent; inline void KMP_T() {
Next[] = ;
for(int i = , j = ; i <= lent; ++i) {
while(j > && t[i] != t[j + ]) j = Next[j];
if(t[i] == t[j + ]) j++;
Next[i] = j;
}
/*for(int i = 1; i <= lent; ++i)
cout << Next[i] << ' ';
cout << '\n';*/
} int main() {
cin >> s + >> t + ;
lens = strlen(s + );
lent = strlen(t + );
KMP_T();
for(int i = ; i <= lens; ++i) {
int j = s2[top];
s1[++top] = s[i];
while(j != && s1[top] != t[j + ]) j = Next[j];
if(s1[top] == t[j + ]) j++;
s2[top] = j;
if(s2[top] == lent) top -= lent;
}
for(int i = ; i <= top; ++i)
cout << s1[i];
cout << '\n';
return ;
}

bzoj3942的更多相关文章

  1. 【BZOJ3940】【BZOJ3942】[Usaco2015 Feb]Censoring AC自动机/KMP/hash+栈

    [BZOJ3942][Usaco2015 Feb]Censoring Description Farmer John has purchased a subscription to Good Hoov ...

  2. bzoj3940&&bzoj3942 Ac自动机||kpm算法

    方法就是维护一个动态栈 记录栈的每一位匹配到串的哪一位的编号 第一道kmp第二道ac自动机 自己理会 #include<cstdio> #include<cstring> #i ...

  3. BZOJ3942 [Usaco2015 Feb]Censoring

    维护一个栈...如果栈顶出现了要被删除的字符串就全删掉就好了,判断的话...kmp就行了 /****************************************************** ...

  4. bzoj3942——2016——3——15

    题目大意: 3942: [Usaco2015 Feb]Censoring Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 220  Solved: 11 ...

  5. BZOJ3942: [Usaco2015 Feb]Censoring 栈+KMP

    Description Farmer John has purchased a subscription to Good Hooveskeeping magazine for his cows, so ...

  6. Bzoj3942 Censoring(KMP)

    \(KMP\)问题的核心在于数组\(next\)(或者\(pre\)/\(fail\),各种叫法),几乎所有的此类型题都是需要计算\(next\)的. 这里解释一波\(next\):即满足字符子串\( ...

  7. 【bzoj3942】[Usaco2015 Feb]Censoring

    [题目大意] 有一个S串和一个T串,长度均小于1,000,000,设当前串为U串,然后从前往后枚举S串一个字符一个字符往U串里添加,若U串后缀为T,则去掉这个后缀继续流程. [样例输入] whatth ...

  8. 【BZOJ3942】Censoring [KMP]

    Censoring Time Limit: 10 Sec  Memory Limit: 128 MB[Submit][Status][Discuss] Description 有一个S串和一个T串,长 ...

  9. 8.8-8.10 usaco

    summary:44 没救了...整天刷水迟早药丸! ❤bzoj3892: 区间dp.我原来的思路是dp[i][j]表示前i个数跳过了j次,那么转移可以前k个数转移了j-1次,枚举k就好了,但是这样是 ...

随机推荐

  1. 在.cs代码文件中无法识别控件

    原因:由于直接复制别人的网页文件到项目. 解决方案,自己右键,新建网页,再把控件代码复制到 aspx和 cs

  2. [Leetcode] Longest consecutive sequence 最长连续序列

    Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...

  3. [Leetcode] Best time to buy and sell stock 买卖股票的最佳时机

    Say you have an array for which the i th element is the price of a given stock on day i. If you were ...

  4. bzoj 2425 [HAOI2010]计数 dp+组合计数

    [HAOI2010]计数 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 451  Solved: 289[Submit][Status][Discus ...

  5. Python之日志操作(logging)

    import logging   1.自定义日志级别,日志格式,输出位置 logging.basicConfig( level=logging.DEBUG, format='%(asctime)s | ...

  6. 使用HTML实现对汉字拼音的支持

    <!DOCTYPE HTML><html> <head> <meta charset="utf-8"> <title>无 ...

  7. 金中欢乐赛 C题

    题目传送门 这道题 hash就可以写了 弄了半天有点智障 强行压一压就okay了的说 #include<cstdio> #include<cstring> #include&l ...

  8. Python 基础总结

    1.执行python脚本的两种方式: 答:1../run.py.shell直接调用python脚本 2.python run.py 调用python 解释器来调用python脚本 5.python单行 ...

  9. 自定义UINavigationController push和pop动画

    http://segmentfault.com/q/1010000000143983 默认的UINavigationController push和pop的默认动画都是左右滑动推出,我的应用要求这种界 ...

  10. CentOS RabbitMQ安装

    1. 安装erlang,参考另外一篇文章: http://www.cnblogs.com/wanpengcoder/p/5287302.html 2. 安装libxslt和: yum install ...