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. laravel5.2 开发中打印sql语句

    在 AppServiceProvider 的boot方法中写入 use DB;use Event; if ( env('APP_ENV') == 'dev' ) { DB::connection()- ...

  2. learning ddr input clock frequency change condition

  3. 【转载】 unity 塔防游戏

    原文地址: Part1的地址:http://www.cnblogs.com/lcxBlog/p/6075984.html Part2的地址:http://www.cnblogs.com/lcxBlog ...

  4. TNetHTTPClient 使用

    unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System ...

  5. day041 前端HTML CSS基本选择器(未整理完毕)

    标签: <b> :加粗 <i> :倾斜体 <u>: 下划线 <s>: 删除线 <p>:段落 <h1> - <h6> ...

  6. js批量上传文件

    html代码: <input type="file" id='upload' name="upload" multiple="multiple& ...

  7. Cracking The Coding Interview 1.6

    //原文: // // Given an image represented by an NxN matrix, where each pixel in the image is 4 bytes, w ...

  8. Centos7扩展存储空间

    1.在关机状态下,在Vm里面设置系统大小到需要的数值 :2.使用root权限登陆linux,df -h查看系统情况: [root@cratedb-hk-01 ~]# df -h 文件系统 容量 已用 ...

  9. springMVC拦截css与js等资源文件的解决

    写了一个demo的ssm,使用jetty容器跑的,但是在页面的时候总是发现访问资源出现404. 换了多种写法不见效. 偶然发现日志中请求被springMVC拦截了,气死我了. 解决方式: Spring ...

  10. struts请求参数注入的三种方式

    .请求参数的注入 在Struts2框架中,表单的提交的数据会自动注入到与Action对象相对应的属性.它与Spring框架中的IoC的注入原理相同,通过Action对象为属性提供setter方法注入 ...