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 ...
随机推荐
- 2015.12.14 MDI(多文档窗口结构)设置基本解决,折腾一天,部分解决存在已久的问题。但效果仍不如临时航线的MDI窗体结构。
创建从一个窗口弹出多个子窗口的结构叫MDI窗体结构 如果不按MDI结构管理,最简单的做法是: 在窗体A上添加菜单或按钮,在菜单或按钮事件中添加弹出B窗体代码: B b = new B(); b.sho ...
- FFmpeg结构体:AVInputFormat
1.描述 AVInputFormat 是类似COM 接口的数据结构,表示输入文件容器格式,着重于功能函数,一种文件容器格式对应一个AVInputFormat 结构,在程序运行时有多个实例,位于avof ...
- sqlplus 设置显示格式
使用sqlplus查询显示结果,显示很乱,下面有种方法可以让她显示的更好看些.1.设置显示的宽度:设置前可以先查看当前宽度: SQL> show linesize;linesize 100SQL ...
- 安卓如何将TXT文件写到特定路径
其实就一个方法,就不贴所有代码了. /** * 写入文件方法 * @param content */ public static void write(String content) { try { ...
- 使用SharedPreferences接口来实现记住密码功能
SharedPreferences接口非常适合用来存储零散的数据.这里我们用来实现记录用户名和密码的功能.在前面我用过IO流来实现记住密码的功能.那么用SharedPreferences接口会比用IO ...
- ORACLE体系结构一 (逻辑结构)-表空间、段、区和数据块
一.Oracle的逻辑结构 Oracle的逻辑结构是一种层次结构.主要由:表空间.段.区和数据块等概念组成.逻辑结构是面向用户的,用户使用Oracle开发应用程序使用的就是逻辑结构.数据库存储层次结构 ...
- springboot启动过程(1)-初始化
1 springboot启动时,只需要调用一个类前面加了@SpringBootApplication的main函数,执行SpringApplication.run(DemoApplication. ...
- Select2下拉选项库 部分积累
用了这么久的Select2插件,也该写篇文章总结总结. 在我的印象里Select2有2个版本,最新版本有一些新的特性,并且更新了一下方法参数,比最初版本要好看一些,本文针对新版本. 官网:http:/ ...
- mysql sequelize 聚合
User.findAll({attributes: [[sequelize.fn('COUNT', sequelize.col('*')), 'email']],raw: true }).then(f ...
- 初步认识ASP.NET WebForm
C#可已进行以下两大类的开发 一.客户端应用程序C/S 主要有两种开发技术: 1.winForm windows窗体应用程序 2.WPF微软新一代图形框架 MFC(比较老的开发技术) MVVM(客户端 ...