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 ...
随机推荐
- NT AUTHORITY\IUSR登录失败解决方法
NT AUTHORITY\IUSR登录失败解决方法 1 今天打开网站时,突然报这个错误,平时都好好的 Cannot open database "aslkm" requested ...
- 用JS实现,图片放大和缩小
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- Markdown简要规则
We believe that writing is about content, about what you want to say – not about fancy formatting. 我 ...
- eclipse 中使用 GreenUML 和 AmasterasUML 自动生成类图
Green UML和AmaterasUML 两种 一.安装方法: 1.都是先安装GEF 通过eclipse-> install new software安装GEF的网址: http://down ...
- 如何让DIALOG点击确定按钮之后由于数据不合法不关闭
public void SetDialogIsClose(DialogInterface pDialog, Boolean pisClose) { try { Field _Field = pDial ...
- php 关于锁的一些看法
背景:在一个项目中,需要一次对数据很复杂的计算,其中一次计算需要花费大概30秒钟时间,大概需要查询一个比较大的表300次左右,然后还需要进行查询7-8次数据库,然后进行组合排序等功能,完成最终结果.对 ...
- 使用ServerSocket建立聊天服务器(二)
-------------siwuxie095 工程名:TestMyServerSocket 包名:com.siwuxie095.socket 类名:M ...
- Java 访问 Kylin 总结
这次开发功能是OEM统计报表.统计报表的数据由大数据平台部的同事收集,数据的展示由我们部门开发. 大数据那边使用 Kylin 分布式分析引擎(kylin官方文档). Kylin 虽比较偏向大数据相关, ...
- iOS 隐藏App图标
1.在进入Info.plist文件 2.在Info.plist文件中新添加一项,把Key值设置为SBAppTags,在Type选项中选取Array 3.在Array中新添加一项Item0,Type类型 ...
- varnish安装
安装pcrevarnish 依赖pcre进行url正则匹配. cd pcre-8.12./configure --prefix=/usr/local/make&&make instal ...