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. python文件管理

    文件没有修改操作,修改的方式为打开文件--读取文件--内存中编辑文件--将内容写入文件 打开文件方式 with open('a.txt','w') as f: #操作系统自动关闭文件 f.write( ...

  2. Win10系列:JavaScript小球运动示例

    通过前面内容的学习,相信读者已经对开发基于JavaScript的Windows应用商店应用有了一定的了解,本小节通过一个小球运动的示例来介绍如何新建一个JavaScript的Windows应用商店项目 ...

  3. OOP⑹

    1.抽象类 所有由abstract关键字修饰的方法我们称之为 抽象方法! 抽象方法只能存在于 抽象类中! 所有由abstract关键字修饰的类我们称之为 抽象类! 抽象类的特点: 01.由abstra ...

  4. Oracle 12c新特性

    转载自:Oracle 12c新特性(For DBA) 一: Multitenant Architecture (12.1.0.1)      多租户架构是Oracle 12c(12.1)的新增重磅特性 ...

  5. MariaDB的线程及连接

    转自 linux公社 今天在这里介绍一下确认mariaDB(和MySQL一样)的链接数及线程数的方法.MariaDB和MySQL有什么不一样,现在还没有弄清楚. 这是减少数据库的负载,并能提高数据库运 ...

  6. 3.1 C++继承的概念及语法

    参考:http://www.weixueyuan.net/view/6358.html. 总结: 继承可以理解为一个类从另一个类获取方法(函数)和属性(成员变量)的过程. 被继承的类称为父类或基类,继 ...

  7. loadrunner http协议性能测试脚本编写

    性能测试其实测的就是接口的性能,不管是用工具录制还是自己写,都是围绕接口的,录制也是把接口录制下来而已,但是录制下来的脚本比较乱,会把很多相关的请求都录下来. 在这里我们手动写HTTP协议的get.p ...

  8. linux安装jdk、tomcat、maven、mysql

    安装SZ rz与Gcc 首先需要tomcat的jar包,打算rz上去,发现没有安装 ./configure的时候发现缺少gcc和cc 安装解决: 再次执行成功安装了sz和rz 创建软链接然后就可以使用 ...

  9. L295 how to turn down a job but keep a good relationship with the hiring manager

    Let’s say you’re on the hunt for a new job. Three interviews in, you realize it’s not the place for ...

  10. day 26面向对象 的封装 接口 抽象

    大纲分析 # 面向对象# 类 :一类具有相同属性和方法的事物 #类的定义:class #类中可以定义的方法种类: #普通方法 self 对象 #类方法 cls @classmethod 类/对象 #静 ...