kuangbin专题十六 KMP&&扩展KMP HDU4300 Clairewd’s message
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.
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.
Range of test data:
T<= 100 ;
n<= 100000;
OutputFor each test case, output one line contains the shorest possible complete text.Sample Input
2
abcdefghijklmnopqrstuvwxyz
abcdab
qwertyuiopasdfghjklzxcvbnm
qwertabcde
Sample Output
abcdabcd
qwertabcde 题目意思非常绕。。。其实就是给你一个加密表,然后给你一个字符串S, 是由密文+明文构成,但是明文可能不完整。所以可以知道密文>=明文 所以就可以把S翻译一下得到T串。 S的后缀是明文(可能不完整) T的前缀是完整明文。
然后S和T匹配。存在这么一个位置 i+extend[i]>=len&&i>extend[i] 说明满足题意
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn=;
int _,Next[maxn],extend[maxn],len;
char table[],S[maxn],T[maxn],temp[]; void getnext() {
Next[]=len;
int j=;
while(j+<len&&T[j]==T[j+]) j++;
Next[]=j;
int k=;
for(int i=;i<len;i++) {
int L=Next[i-k],p=k+Next[k]-;
if(i+L<p+) Next[i]=L;
else {
j=max(,p-i+);
while(i+j<len&&T[i+j]==T[j]) j++;
Next[i]=j;
k=i;
}
}
} void getextend() {
getnext();
int j=;
while(j<len&&T[j]==S[j]) j++;
extend[]=j;
int k=;
for(int i=;i<len;i++) {
int L=Next[i-k],p=k+extend[k]-;
if(i+L<p+) extend[i]=L;
else {
j=max(,p-i+);
while(i+j<len&&S[i+j]==T[j]) j++;
extend[i]=j;
k=i;
}
}
} int main() {
//freopen("in","r",stdin);
for(scanf("%d",&_);_;_--) {
scanf("%s%s",table,S);
len=strlen(S);
for(int i=;i<;i++)
temp[table[i]]='a'+i;
for(int i=;i<len;i++)
T[i]=temp[S[i]];
T[len]='\0';
getextend();
int i;
for(i=;i<len;i++) {
if(i+extend[i]>=len&&i>=extend[i]) break;
}
for(int j=;j<i;j++) printf("%c",S[j]);
for(int j=;j<i;j++) printf("%c",T[j]);
printf("\n");
}
}
kuangbin专题十六 KMP&&扩展KMP HDU4300 Clairewd’s message的更多相关文章
- kuangbin专题十六 KMP&&扩展KMP HDU2609 How many (最小字符串表示法)
Give you n ( n < 10000) necklaces ,the length of necklace will not large than 100,tell me How man ...
- kuangbin专题十六 KMP&&扩展KMP HDU2328 Corporate Identity
Beside other services, ACM helps companies to clearly state their “corporate identity”, which includ ...
- kuangbin专题十六 KMP&&扩展KMP HDU1238 Substrings
You are given a number of case-sensitive strings of alphabetic characters, find the largest string X ...
- kuangbin专题十六 KMP&&扩展KMP HDU3336 Count the string
It is well known that AekdyCoin is good at string problems as well as number theory problems. When g ...
- kuangbin专题十六 KMP&&扩展KMP POJ3080 Blue Jeans
The Genographic Project is a research partnership between IBM and The National Geographic Society th ...
- kuangbin专题十六 KMP&&扩展KMP HDU3746 Cyclic Nacklace
CC always becomes very depressed at the end of this month, he has checked his credit card yesterday, ...
- kuangbin专题十六 KMP&&扩展KMP HDU2087 剪花布条
一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图案.对于给定的花布条和小饰条,计算一下能从花布条中尽可能剪出几块小饰条来呢? Input输入中含有一些数据,分别是成对出现的花布条和小 ...
- kuangbin专题十六 KMP&&扩展KMP HDU1686 Oulipo
The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e ...
- kuangbin专题十六 KMP&&扩展KMP HDU1711 Number Sequence
Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], ...... , b[M] (1 <= M ...
随机推荐
- 使用jmx4perl和j4psh接管Jolokia
在ActiveMQ的API中,内置了Jolokia . 可以使用jmx4perl来安装: $ perl -MCPAN -e shell Terminal does not support AddHis ...
- Ubuntu bash不记录history方法
很多都是用: unset HISTORY HISTFILE HISTSAVE HISTZONE HISTORY HISTLOG export HISTFILE=/dev/null export HIS ...
- 今天出现编码出现了No suitable driver found for jdbc
出现这样的情况,一般有四种原因: 一:连接URL格式出现了问题(Connection conn=DriverManager.getConnection("jdbc:mysql://local ...
- maven中pom.xml元素含义
- tortoisesvn 本项目的忽略项
https://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-dug-propertypage.html Adding and Editing Pr ...
- String/StringBuilder 类 统计字符串中字符出现的次数
1.1. 训练描述:[方法.String类] 一.需求说明:定义如下字符串: String str = “javajfiewjavajfiowfjavagkljjava”; 二.请分别定义方法统计出: ...
- 仿射变换详解 warpAffine
转自 http://www.cnblogs.com/dupuleng/articles/4055020.html 博客园 首页 新随笔 联系 管理 订阅 随笔- 1 文章- 185 评论- 14 ...
- STM32 C++编程 003 USART(串口)类
使用 C++ 语言给 STM32 编写一个 Usart 类 我使用的STM32芯片:STM32F103ZET6 我们使用的STM32库版本:V3.5.0 注意: 想学习本套 STM32 C++编程 的 ...
- R: 关于 ggplot2 的初探
生活还很长,别急,慢慢来.亲爱的 require(ggplot2)p1 <- ggplot(mpg, aes(displ, hwy)) + geom_point() ; p1p1 + scale ...
- 715B Complete The Graph
传送门 题目大意 给出一个图,一些边带权,另一些边等待你赋权(最小赋为1).请你找到一种赋权方式,使得 s 到 t 的最短路为 L n ≤ 1e3 ,m ≤ 1e4 ,L ≤ 1e9 分析 二分所有边 ...