题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4300

Problem Description
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.
 
Input
The first line contains only one integer T, which is the number of test cases.

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.

Hint

Range of test data:

T<= 100 ;

n<= 100000;

 
Output
For each test case, output one line contains the shorest possible complete text.
 
Sample Input
2
abcdefghijklmnopqrstuvwxyz
abcdab
qwertyuiopasdfghjklzxcvbnm
qwertabcde
 
Sample Output
abcdabcd
qwertabcde
 
Author
BUPT
 
Source

题意:

比較难理解,给定两组字符串,第一组仅仅有26个字符表相应明文中a,b,c,d....z能够转换第1个,第2个...第26个字符变成密文,

第二组字符串是给定的密文+明文,明文可能不完整(缺失或没有),叫你补充完整整个密文+明文是最短的;

PS:读了好几遍都不理解题意。用了翻译工具还是不能理解。最后还是百度了才知道题意!(毕竟英语太渣)。

思路:

把给出的不完整的明文加密文字符串所有转换一次。将转换后的做模式串,与原串进行kmp,记录返回的j值(j值代表的就是前缀和后缀的最长相等长度)。然后再与给出的明文加密文字符串比較一下。

代码例如以下:

//#pragma warning (disable:4786)
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <cstdlib>
#include <climits>
#include <ctype.h>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <deque>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
const double eps=1e-9;
const double pi=3.1415926535897932384626;
#define INF 1e18
//typedef long long LL;
//typedef __int64 LL;
const int MAXN = 100017; char strm[MAXN];//password表
char strz[MAXN];//不完整的密文和密文
char str[MAXN]; //password表转换后
char s[MAXN]; //密文和明文转换后
int next[MAXN]; void getnext( char T[], int len)
{
int i = 0, j = -1;
next[0] = -1;
while(i < len)
{
if(j == -1 || T[i] == T[j])
{
i++, j++;
next[i] = j;
}
else
j = next[j];
}
}
int KMP(int len1, int len2)
{
int i, j = 0;
if(len1%2 == 1)
{
i = len1/2+1;
}
else
i = len1/2;
while(i < len1 && j < len2)
{
if(j == -1 || strz[i] == s[j])
{
i++, j++;
}
else
j = next[j];
}
return j;//j值代表的就是前缀和后缀的最长相等长度
} int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%s",strm);
for(int i = 0; i < 26; i++)
{
char ss = strm[i];
str[ss] = i;
}
scanf("%s",strz);
int lenz = strlen(strz);
for(int i = 0; i < lenz; i++)//将密文和明文依照password表转换
{
int tt = str[strz[i]];
s[i] = 'a' + tt;
}
int lens = strlen(s);
getnext(s, lens);
int j = KMP(lenz, lens);//得到密文的个数
if(j*2 == lenz)//前缀和后缀恰各占一半
{
printf("%s\n",strz);
}
else
{
int tt = lenz - j;
printf("%s",strz);
for(int i = j; i < tt; i++)//须要加入的明文
{
printf("%c",s[i]);
}
printf("\n");
}
}
return 0;
}

hdu 4300 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/扩展kmp)

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

  3. hdu 4300 Clairewd’s message KMP应用

    Clairewd’s message 题意:先一个转换表S,表示第i个拉丁字母转换为s[i],即a -> s[1];(a为明文,s[i]为密文).之后给你一串长度为n<= 100000的前 ...

  4. hdu 4300 Clairewd’s message 字符串哈希

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

  5. HDU - 4300 Clairewd’s message (拓展kmp)

    HDU - 4300 题意:这个题目好难读懂,,先给你一个字母的转换表,然后给你一个字符串密文+明文,密文一定是全的,但明文不一定是全的,求最短的密文和解密后的明文: 题解:由于密文一定是全的,所以他 ...

  6. HDU 4300 Clairewd’s message(扩展KMP)

    思路:extend[i]表示原串以第i開始与模式串的前缀的最长匹配.经过O(n)的枚举,我们能够得到,若extend[i]+i=len且i>=extend[i]时,表示t即为该点之前的串,c即为 ...

  7. HDU 4300 Clairewd’s message(扩展KMP)题解

    题意:先给你一个密码本,再给你一串字符串,字符串前面是密文,后面是明文(明文可能不完成整),也就是说这个字符串由一个完整的密文和可能不完整的该密文的明文组成,要你找出最短的密文+明文. 思路:我们把字 ...

  8. HDU 4300 Clairewd’s message(KMP+思维)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4300 题目大意:题目大意就是给以一段字符xxxxzzz前面x部分是密文z部分是明文,但是我们不知道是从 ...

  9. 【HDU 4300 Clairewd’s message】

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

随机推荐

  1. 搭建基于金山快盘的Git服务器

    最近迷上了Git,这货堪称神器,用了它就再也不想用其他VCS了,就像上了高速就不想再走国道一样. 一般人使用Git+Github来搭建进行本地远程交互,不过Github弄个私人仓库是要刀乐思的,如果你 ...

  2. Activity树图

  3. Codeforces Round #410 (Div. 2) B. Mike and strings

    B. Mike and strings time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  4. 再谈 Go 语言在前端的应用前景

    12 月 23 日,七牛云 CEO & ECUG 社区发起人许式伟先生在 ECUG Con 2018 现场为大家带来了主题为<再谈 Go 语言在前端的应用前景>的内容分享. 本文是 ...

  5. 洛谷P2664 树上游戏 【点分治 + 差分】

    题目 lrb有一棵树,树的每个节点有个颜色.给一个长度为n的颜色序列,定义s(i,j) 为i 到j 的颜色数量.以及 现在他想让你求出所有的sum[i] 输入格式 第一行为一个整数n,表示树节点的数量 ...

  6. java面试题之为什么hashmap的数组初始化大小都是2的N次方?

    当数组长度为2的N次方时,不同的key算出的index相同的几率小,数据在数组上分配均匀,hash碰撞的几率小,提升查询效率,从大O(N)提升至O(1):

  7. Ubuntu12.04 64bit版本下载Android源码完整教程

    首先去官网http://source.android.com/source/initializing.html可以看到完整的安装教程.不过一般情况下,按照这个教程是无法一步到位的,因为中途肯定会遇到很 ...

  8. 从实际案例聊聊Java应用的GC优化

    转自美团点评技术博客:https://tech.meituan.com/jvm_optimize.html 当Java程序性能达不到既定目标,且其他优化手段都已经穷尽时,通常需要调整垃圾回收器来进一步 ...

  9. es6模板语法使用上的一点问题

    var str = "test"; console.log(str); // test console.log(`str`) //str 这里的str是模板语法里面的,而不是变量s ...

  10. iframe平铺到浏览器

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...