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 ...
随机推荐
- 问题:Oracle 树形遍历;结果:使用oracle进行遍历树操作
使用oracle进行遍历树操作 1:首先数据库中表必须是树形结构的 2:super_department_id 为 department_id 的父节点编号 3:以下语句的执行结果是:depart ...
- CALayer的基本使用
CALayer需要导入这个框架:#import <QuartzCore/QuartzCore.h> 一.CALayer常用属性 属性 说明 是否支持隐式动画 anchorPoint 和中心 ...
- CentOS6.5 增加交换空间
在CentOS 6.5安装Oracle 11g的时候,提示交换空间不足,百度来下,找到来增加交换空间的方法,特此记录一下 增加交换空间有两种方法: 严格的说,在系统安装完后只有一种方法可以增加swap ...
- day17-jdbc 8.ResultSet介绍
但是这些东西在mysql那里有问题.mysql的驱动不是很完善.getClob().getBlob()不好使不是因为程序的问题,而是因为mysql驱动的问题,oracle驱动就没有这个问题,证明ora ...
- c++11: thread_local
thread_local变量是C++ 11新引入的一种存储类型.它会影响变量的存储周期(Storage duration),C++中有4种存储周期: automatic static dynamic ...
- Ros学习——launch文件解析
launch文件的重点是:节点(node)元素的集合. roslaunch 则是让所有的节点共享同一个终端. 1.标签(元素)说明 1. group标签 2. node标签 <group ns= ...
- Blender 安装
Blender 安装 Blender 安装 windows 上安装 Blender 搞定 Ubuntu Linux 上安装 Blender 搞定 windows 上安装 Blender Step 1 ...
- Camera 3D概念
1. integration time即积分时间是以行为单位表示曝光时间(exposure time)的,比如说INT TIM为159,就是指sensor曝光时间为159行,两者所代表的意思是相同的, ...
- ZROI2018提高day5t1
传送门 分析 我们不难将条件转换为前缀和的形式,即 pre[i]>=pre[i-1]*2,pre[i]>0,pre[k]=n. 所以我们用dp[i][j]表示考虑到第i个数且pre[i]= ...
- Luogu 3530 [POI2012]FES-Festival
我是真的不会写差分约束啊呜呜呜…… BZOJ 2788被权限了. 首先对于第一个限制$x + 1 = y$,可以转化成$x + 1 \leq y \leq x + 1$, 所以连一条$(y, x, - ...