地址:http://acm.hdu.edu.cn/showproblem.php?pid=4300

题目:

Clairewd’s message

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6347    Accepted Submission(s): 2381

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
 
思路:扩展kmp+枚举
 #include<iostream>
#include<string>
#include<cstring>
#include<cstdio> using namespace std;
const int K=1e6+;
int nt[K],extand[K];
char S[K],T[K],sa[K],tr[];
void Getnext(char *T,int *next)
{
int len=strlen(T),a=;
next[]=len;
while(a<len- && T[a]==T[a+]) a++;
next[]=a;
a=;
for(int k=; k<len; k++)
{
int p=a+next[a]-,L=next[k-a];
if( (k-)+L >= p)
{
int j = (p-k+)> ? (p-k+) : ;
while(k+j<len && T[k+j]==T[j]) j++;
next[k]=j;
a=k;
}
else
next[k]=L;
}
}
void GetExtand(char *S,char *T,int *next)
{
Getnext(T,next);
int slen=strlen(S),tlen=strlen(T),a=;
int MinLen = slen < tlen ? slen : tlen;
while(a<MinLen && S[a]==T[a]) a++;
extand[]=a;
a=;
for(int k=; k<slen; k++)
{
int p=a+extand[a]-, L=next[k-a];
if( (k-)+L >= p)
{
int j= (p-k+) > ? (p-k+) : ;
while(k+j<slen && j<tlen && S[k+j]==T[j]) j++;
extand[k]=j;
a=k;
}
else
extand[k]=L;
}
}
int main(void)
{
int t;cin>>t;
while(t--)
{
scanf("%s%s",S,T);
int len=strlen(T),st=;
for(int i=;i<;i++)
tr[S[i]]='a'+i;
for(int i=;i<len;i++)
sa[i]=tr[T[i]];
sa[len]=T[len];
GetExtand(T,sa,nt);
for(int i=(len+)/;i<len&&!st;i++)
if(extand[i]==len-i)
st=i-;
if(st==)st=len-;
for(int i=;i<=st;i++)
printf("%c",T[i]);
for(int i=;i<=st;i++)
printf("%c",tr[T[i]]);
printf("\n"); }
return ;
}

hdu4300 Clairewd’s message的更多相关文章

  1. hdu------(4300)Clairewd’s message(kmp)

    Clairewd’s message Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  2. HDU-4300 Clairewd’s message

    http://acm.hdu.edu.cn/showproblem.php?pid=4300 很难懂题意.... Clairewd’s message Time Limit: 2000/1000 MS ...

  3. hdu4300 Clairewd’s message【next数组应用】

    Clairewd’s message Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  4. hdu4300 Clairewd’s message 扩展KMP

    Clairewd is a member of FBI. After several years concealing in BUPT, she intercepted some important ...

  5. kuangbin专题十六 KMP&&扩展KMP HDU4300 Clairewd’s message

    Clairewd is a member of FBI. After several years concealing in BUPT, she intercepted some important ...

  6. HDU4300 Clairewd’s message(拓展kmp)

    Problem Description Clairewd is a member of FBI. After several years concealing in BUPT, she interce ...

  7. hdu 4300 Clairewd’s message KMP应用

    Clairewd’s message 题意:先一个转换表S,表示第i个拉丁字母转换为s[i],即a -> s[1];(a为明文,s[i]为密文).之后给你一串长度为n<= 100000的前 ...

  8. (KMP 扩展)Clairewd’s message -- hdu -- 4300

    http://acm.hdu.edu.cn/showproblem.php?pid=4300 Clairewd’s message Time Limit: 2000/1000 MS (Java/Oth ...

  9. hdu 4300 Clairewd’s message 字符串哈希

    Clairewd’s message Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

随机推荐

  1. C#中动态调用DLL动态链接库

    其中要使用两个未公开的Win32 API函数来存取控制台窗口,这就需要使用动态调用的方法,动态调用中使用的Windows API函数主要有三个,即:Loadlibrary,GetProcAddress ...

  2. word excel文件 存入数据库 实战

    上传: private void Insert2017(HttpContext context) { if (context.Request.Files["fileword"].C ...

  3. POJ2456 Aggressive cows(二分+贪心)

    如果C(d)为满足全部牛之间的距离都不小于d. 先对牛舍的位置排序,然后二分枚举d,寻找满足条件的d. #include<iostream> #include<cstdio> ...

  4. docker harbor 安装 使用总结

    总结:没有验证,但是猜测. 我这个harbor的机器上  有起了一个 docker的 registry, 5000端口的,不知道是不是二者冲突. 猜测是这个情况. 1. 安装参考 收藏的链接 1.1  ...

  5. R语言中的Apriori关联规则的使用

    1.下载Matrix和arules包 install.packages(c("Matrix","arules")) 2.载入引入Matrix和arules包 # ...

  6. PHP使用 DOMDocument创建和解析xml文件

    <!-- DOMDocument生成XML文件 --><?php//声明一个DOMDocument对象$_doc=new DOMDocument('1.0', 'utf-8'); / ...

  7. 【转载】Java并发编程:volatile关键字解析

    http://www.cnblogs.com/dolphin0520/p/3920373.html

  8. Nagle's algorithm

    w41字节的数据包只有1字节的可用信息.以减少数据包发送量来提高TCP/IP网络性能. https://en.wikipedia.org/wiki/Nagle's_algorithm https:// ...

  9. C#、devExpress 的 给bandedGrid加菜单功能 :复制、粘贴的例子(转)

    C#.devExpress 的 给bandedGrid加菜单功能 :复制.粘贴的例子 CopyFromGrid PasteToGrid PasteNewRowsToGrid private void ...

  10. QT in VS 多语言实现(中英文切换,每个步骤都有截图,只有UTF8才能让Qt语言家正确读取。先qApp->removeTranslator,然后installTranslator,每个类都要写上槽函数RetranslateUI)

    最近项目需要软件具有中英文双语切换功能,而QT又自带此功能,现将实现方式记录下来. 说到中英文切换,少不了要了解QT的内部编码方式.在此就不详述QT编码方式了,具体可参考 彻底弄懂Qt的编码.只需要记 ...