hdu 4300 Clairewd’s message(扩展kmp)
Unfortunately, GFW(someone's name, not what you just think about) has detected their action. He also got their conversion table by some unknown methods before. Clairewd was so clever and vigilant that when she realized that somebody was monitoring their action, she just stopped transmitting messages.
But GFW knows that Clairewd would always firstly send the ciphertext and then plaintext(Note that they won't overlap each other). But he doesn't know how to separate the text because he has no idea about the whole message. However, he thinks that recovering the shortest possible text is not a hard task for you.
Now GFW will give you the intercepted text and the conversion table. You should help him work out this problem.
Each test case contains two lines. The first line of each test case is the conversion table S. S[i] is the ith latin letter's cryptographic letter. The second line is the intercepted text which has n letters that you should recover. It is possible that the text is complete.
Range of test data:
T<= 100 ;
n<= 100000;
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#define ll long long int
using namespace std;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int moth[]={,,,,,,,,,,,,};
int dir[][]={, ,, ,-, ,,-};
int dirs[][]={, ,, ,-, ,,-, -,- ,-, ,,- ,,};
const int inf=0x3f3f3f3f;
const ll mod=1e9+;
int nextt[+];
int ex[+];
void getnext(string s){
int len=s.length(); int po;
nextt[]=len;
int pos=;
while(s[pos+]==s[pos]&&pos<len-) pos++;
nextt[]=pos;
po=;
for(int i=;i<len;i++){
if(nextt[i-po]+i<nextt[po]+po)
nextt[i]=nextt[i-po];
else{
int j=po+nextt[po]-i;
if(j<) j=;
while(i+j<len&&s[j]==s[i+j]) j++;
nextt[i]=j;
}
}
}
void getex(string t,string p){
int len1=p.length(); int len2=t.length();
int po;
getnext(t);
int pos=;
while(t[pos]==p[pos]&&pos<len1&&pos<len2) pos++;
ex[]=pos;
po=;
for(int i=;i<len1;i++){
if(nextt[i-po]+i<po+ex[po])
ex[i]=nextt[i-po];
else{
int j=po+ex[po]-i;
if(j<) j=;
while(i+j<len1&&j<len2&&t[j]==p[i+j]) j++;
ex[i]=j;
}
}
}
int main(){
ios::sync_with_stdio(false);
int t;
cin>>t;
while(t--){
string tab;
map<char,char> mm;
string tx;
cin>>tab>>tx;
string ctx="";
for(int i=;i<tab.length();i++){
mm[tab[i]]=i+'a'; //解码
}
int len=tx.length();
for(int i=;i<len;i++)
ctx+=mm[tx[i]];
getex(ctx,tx);
string ans="";
int k;
for(k=(len+)/;k<len;k++)
if(k+ex[k]==len) //k+ex值如果等于len 说明这个就是后缀
break;
for(int i=;i<k;i++)
ans+=tx[i];
for(int i=;i<k;i++)
ans+=mm[tx[i]];
cout<<ans<<endl;
}
return ;
}
hdu 4300 Clairewd’s message(扩展kmp)的更多相关文章
- hdu 4300 Clairewd’s message(kmp/扩展kmp)
题意:真难懂.. 给出26个英文字母的加密表,明文中的'a'会转为加密表中的第一个字母,'b'转为第二个,...依次类推. 然后第二行是一个字符串(str1),形式是密文+明文,其中密文一定完整,而明 ...
- HDU 4300 Clairewd's message ( 拓展KMP )
题意 : 给你一个包含26个小写字母的明文密文转换信息字符串str,第一个表示'a'对应的密文是str[0].'b'对应str[1]……以此类推.接下来一行给你一个另一个字符串,这个字符串由密文+明文 ...
- hdu 4300 Clairewd’s message KMP应用
Clairewd’s message 题意:先一个转换表S,表示第i个拉丁字母转换为s[i],即a -> s[1];(a为明文,s[i]为密文).之后给你一串长度为n<= 100000的前 ...
- HDU - 4300 Clairewd’s message (拓展kmp)
HDU - 4300 题意:这个题目好难读懂,,先给你一个字母的转换表,然后给你一个字符串密文+明文,密文一定是全的,但明文不一定是全的,求最短的密文和解密后的明文: 题解:由于密文一定是全的,所以他 ...
- hdu4300 Clairewd’s message 扩展KMP
Clairewd is a member of FBI. After several years concealing in BUPT, she intercepted some important ...
- hdu 4300 Clairewd’s message 字符串哈希
Clairewd’s message Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- hdu 4300 Clairewd’s message(具体解释,扩展KMP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4300 Problem Description Clairewd is a member of FBI. ...
- HDU 4300 Clairewd’s message(扩展KMP)
思路:extend[i]表示原串以第i開始与模式串的前缀的最长匹配.经过O(n)的枚举,我们能够得到,若extend[i]+i=len且i>=extend[i]时,表示t即为该点之前的串,c即为 ...
- HDU 4300 Clairewd’s message(扩展KMP)题解
题意:先给你一个密码本,再给你一串字符串,字符串前面是密文,后面是明文(明文可能不完成整),也就是说这个字符串由一个完整的密文和可能不完整的该密文的明文组成,要你找出最短的密文+明文. 思路:我们把字 ...
随机推荐
- Oracle 表空间不足引起的问题及解决方法
-- 1 向数据库导入数据时报了ORA-01653: unable to extend table错误,网上查了下原因是由于表空间不足引起的: 查询表空间使用情况语句 select a.tablesp ...
- mysql实现首字母从A-Z排序
1.常规排序ASC DESC ASC 正序 DESC倒叙 -- 此处不用多讲 2.自定义排序 自定义排序是根据自己想要的特定字符串(数字)顺序进行排序.主要是使用函数 FIELD(str,str1,s ...
- [官网]How to use distributed transactions with SQL Server on Docker
How to use distributed transactions with SQL Server on Docker https://docs.microsoft.com/en-us/sql/l ...
- 调整分区大小 转载--------------http://blog.csdn.net/perfectzq/article/details/73606119
centos7重新调整分区大小 centos 7 调整 root 和 home 的容量大小 查看磁盘的空间大小: df -h 备份/home : cp -r /home/ homebak/ 卸载 ...
- springboot+ELK+logback日志分析系统demo
之前写的有点乱,这篇整理了一下搭建了一个简单的ELK日志系统 借鉴此博客完成:https://blog.csdn.net/qq_22211217/article/details/80764568 设置 ...
- 谈谈B-树和B+树及其应用
待更!!! B-树和B+树的应用:数据搜索和数据库索引 B+/-Tree原理及mysql的索引分析 从B树.B+树.B*树谈到R 树 B树.B-树.B+树.B*树
- Flutter上拉加载下拉刷新---flutter_easyrefresh
前言 Flutter默认不支持上拉加载,下拉刷新也仅仅支持Material的一种样式.Android开发使用过SmartRefreshLayout的小伙伴都知道这是一个强大的刷新UI库,集成了很多出色 ...
- Netty ByteBuf和Nio ByteBuffer
参考https://blog.csdn.net/jeffleo/article/details/69230112 一.简介 Netty中引入了ByteBuf,它相对于ByteBuffer来说,带来了很 ...
- Spring拦截器(学习笔记)
SpringMVC 中的Interceptor 拦截请求是通过HandlerInterceptor 来实现的 在SpringMVC 中定义一个Interceptor 非常简单,主要有两种方式 第一种方 ...
- Promise是什么?
一. Promise是什么? Promise是一种异步操作的解决方案,将写法复杂的传统的回调函数和监听事件的异步操作,用同步代码的形式表达出来. 避免了多级异步操作的回调函数嵌套. Promise最早 ...