Clairewd is a member of FBI. After several years concealing in BUPT, she intercepted some important messages and she was preparing for sending it to ykwd. They had agreed that each letter of these messages would be transfered to another one according to a conversion table.
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.

题意:有一个字母映射的表作为加密表,有一段密文和一段明文连接成一个字符串,现在给出这个串的整个密文和部分明文,要恢复出最短可能的密文+明文。

用扩展KMP将串与本身依靠加密表进行处理,然后求出匹配的最长明文后缀,但是要注意,匹配长度必须小于等于串长。

 #include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std; const int maxn=1e5+; char ct[];
char s[maxn],tmp[maxn];
int ext[maxn],nxt[maxn]; void EKMP(char s[],char t[],int lens,int lent){
int i,j,p,l,k;
nxt[]=lent;j=;
while(j+<lent&&t[j]==t[j+])j++;
nxt[]=j;
k=;
for(i=;i<lent;i++){
p=nxt[k]+k-;
l=nxt[i-k];
if(i+l<p+)nxt[i]=l;
else{
j=max(,p-i+);
while(i+j<lent&&t[i+j]==t[j])j++;
nxt[i]=j;
k=i;
}
} j=;
while(j<lens&&j<lent&&s[j]==t[j])j++;
ext[]=j;k=;
for(i=;i<lens;i++){
p=ext[k]+k-;
l=nxt[i-k];
if(l+i<p+)ext[i]=l;
else{
j=max(,p-i+);
while(i+j<lens&&j<lent&&s[i+j]==t[j])j++;
ext[i]=j;
k=i;
}
}
} int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%s%s",ct,s);
int len=strlen(s);
for(int i=;i<len;++i)tmp[i]=ct[s[i]-'a'];
EKMP(tmp,s,len,len);
int i;
for(i=(len+)/;i<len;++i){
if(ext[i]==len-i){
break;
}
}
i--;
for(int j=;j<=i;++j)putchar(s[j]);
for(int j=;j<=i;++j){
for(int k=;k<;++k){
if(ct[k]==s[j]){
putchar('a'+k);
break;
}
}
}
printf("\n");
}
return ;
}

hdu4300 Clairewd’s message 扩展KMP的更多相关文章

  1. hdu 4300 Clairewd’s message(扩展kmp)

    Problem Description Clairewd is a member of FBI. After several years concealing in BUPT, she interce ...

  2. hdu------(4300)Clairewd’s message(kmp)

    Clairewd’s message Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  3. hdu 4300 Clairewd’s message(kmp/扩展kmp)

    题意:真难懂.. 给出26个英文字母的加密表,明文中的'a'会转为加密表中的第一个字母,'b'转为第二个,...依次类推. 然后第二行是一个字符串(str1),形式是密文+明文,其中密文一定完整,而明 ...

  4. HDU-4300-Clairewd's message(扩展KMP)

    链接: https://vjudge.net/problem/HDU-4300 题意: Clairewd is a member of FBI. After several years conceal ...

  5. hdu4300 Clairewd’s message

    地址:http://acm.hdu.edu.cn/showproblem.php?pid=4300 题目: Clairewd’s message Time Limit: 2000/1000 MS (J ...

  6. HDU-4300 Clairewd’s message

    http://acm.hdu.edu.cn/showproblem.php?pid=4300 很难懂题意.... Clairewd’s message Time Limit: 2000/1000 MS ...

  7. hdu4300 Clairewd’s message【next数组应用】

    Clairewd’s message Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  8. kuangbin专题十六 KMP&&扩展KMP HDU4300 Clairewd’s message

    Clairewd is a member of FBI. After several years concealing in BUPT, she intercepted some important ...

  9. HDU4300 Clairewd’s message(拓展kmp)

    Problem Description Clairewd is a member of FBI. After several years concealing in BUPT, she interce ...

随机推荐

  1. 尚学堂java 答案解析 第四章

    本答案为本人个人编辑,仅供参考,如果读者发现,请私信本人或在下方评论,提醒本人修改 一.选择题 1.BD 解析:B:类必须有构造方法,若程序未写,这系统自动调用系统构造方法. D:super()会调用 ...

  2. sqlalchemy动态组合查询语句。

    if filter_type == 1: search = and_(GameRoom.status ==1,or_( and_(GameRoom.white_user_id == user_id, ...

  3. 《Python》常用模块之collections模块

    内置的数据类型: int  float  complex str  list  tuple dict  set 基础数据类型: int  float  complex str  list  tuple ...

  4. [Linux]Linux下Apache服务器配置

    Linux下Apache服务器配置 相关包: httpd-2.2.3-29.e15.i386.rpm                 //主程序包 httpd-devel-2.2.3-29.e15.i ...

  5. 三. Python基础(3)--语法

    三. Python基础(3)--语法 1. 字符串格式化的知识补充 tpl = "我是%s,年龄%d,学习进度100%" %('Arroz',18) print(tpl) # 会提 ...

  6. sass 继承 占位符 %placeholder

    @extend //SCSS .btn { border: 1px solid #ccc; padding: 6px 10px; font-size: 14px; } .btn-primary { b ...

  7. 在嵌入式设计中使用MicroBlaze(Vivado版本)(转)

    原文Xilinx官方文档<ug898-vivado-embedded-design>第三章 一.MicroBlaze处理器设计介绍(略) 二.创建带有MicroBlaze处理器的IP设计 ...

  8. python笔记7-if中的is ;in ;not搭配用法

    names="111 222 333" print("111" in names)#返回的是True,用in返回的是布尔值in在里面 print("1 ...

  9. mvc Model验证总结及常用正则表达式

    本文属转载,来源: http://www.byywee.com/page/M0/S868/868615.html 关于Model验证官方资料: http://msdn.microsoft.com/zh ...

  10. pycharm 永久解封

    第一步   c:\windows\system32\drivers\etc    命令行输入这个 第二步     把host文件复制到桌面 第三步   记事本打开host 第四步    在最下面添加  ...