题目链接: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. github仓库主页介绍

  2. luogu3178 [HAOI2015]树上操作

    裸题 #include <iostream> #include <cstdio> using namespace std; typedef long long ll; int ...

  3. 零基础学 JavaScript 全彩版 明日科技 编著

    第1篇 基础知识 第1章 JavaScript简介 1.1 JavaScript简述 1.2 WebStorm的下载与安装 1.3 JavaScript在HTML中的使用 1.3.1 在页面中直接嵌入 ...

  4. python中用exit退出程序

    在python中运行一段代码,如果在某处已经完成整次任务,可以用exit退出整个运行.并且还可以在exit()的括号里加入自己退出程序打印说明.不过注意在py3中要加单引号或双引号哦!

  5. SparkStreaming 编程指南

    摘要:学习SparkStreaming从官网的编程指南开始,由于Python编码修改方便不用打包,这里只整理python代码! 一.概述 Spark Streaming 是 Spark Core AP ...

  6. 【bzoj2698】染色 期望

    题目描述 输入 输入一行四个整数,分别为N.M.S和T. 输出 输出一行为期望值,保留3位小数. 样例输入 5 1 2 3 样例输出 2.429 题解 期望 由于期望在任何时候都是可加的,因此只要算出 ...

  7. HDU——4162Shape Number(字符串的最小表示)

    Shape Number Time Limit: 24000/12000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  8. [luoguP2569] [SCOI2010]股票交易(DP + 单调队列)

    传送门 $f[i][j]$ 表示第i天,手中股票数为j的最优解 初始化 $f[i][0]=0$ $0<=i<=n$ 4种方式转移 以前没买过,第i天凭空买 $f[i][j]=-j*ap$ ...

  9. .net EF框架

    https://blog.csdn.net/u012235352/article/details/82768897 model first https://blog.csdn.net/u0101783 ...

  10. System and method for cache management

    Aspects of the invention relate to improvements to the Least Recently Used (LRU) cache replacement m ...