题目链接:

pid=4300">http://acm.hdu.edu.cn/showproblem.php?pid=4300

题目意思真的非常难读懂。

题意:给定两组字符串,第一组仅仅有26个字符表相应明文中a,b,c,d....z能够转换第一个,第二个...第26个字符变成密文,

第二组字符串是给定的密文+明文,明文可能不完整(缺失或没有),叫你补完且整个密文+明文是最短的

假设有多种明文则取最大的明文。

解题思路就是将前一半一定是密文的字符装换成明文。然后+后面的字符,从后往前匹配,匹配小于等于长度一半的最长前缀;

#include<map>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<stack>
#include<cstring>
#include<set>
#include<vector>
#include<algorithm>
#define LL long long
#define inf 1<<30
#define s(a) scanf("%d",&a)
#define CL(a,b) memset(a,b,sizeof(a))
using namespace std;
const int N=200005;
int n,m;
char a[N],b[N];
char num[N];
char c[N];
int nnext[N];
void get_nnext(char *a,int len)
{
int j=-1,i=0;
nnext[0]=-1;
while(i<len){
if(j == -1 || a[i] == a[j]) nnext[++i]=++j;
else j=nnext[j];
}
}
int main()
{
int t;
cin>>t;
while(t--){
cin>>a>>b;
int len=strlen(b),k=len;
for(int i=0;i<26;i++) num[a[i]-'a']='a'+i;
for(int i=0;i<(len+1)/2;i++) c[i]=num[b[i]-'a']; // 将前一部分转换成密文。
for(int i=(len+1)/2;i<=len;i++) c[i]=b[i]; // 拼接后一部分明文;
get_nnext(c,len);
while(nnext[k]>len/2) k=nnext[k]; // 从后往前匹配;寻找长度小于len的最长前缀;
cout<<b;
for(int i=nnext[k];i<len-nnext[k];i++) cout<<num[b[i]-'a']; // 输出还不够的字符串。须要注意点的是这里输出的解密的字符,而不能直接用c[i];
cout<<endl;
}
return 0;
}

HDU4300-Clairewd’s message-KMP的更多相关文章

  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 KMP应用

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

  3. HDU-4300 Clairewd’s message

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

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

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

  5. hdu4300 Clairewd’s message

    地址:http://acm.hdu.edu.cn/showproblem.php?pid=4300 题目: Clairewd’s message Time Limit: 2000/1000 MS (J ...

  6. hdu4300 Clairewd’s message 扩展KMP

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

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

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

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

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

  9. HDU 4300 Clairewd’s message(KMP+思维)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4300 题目大意:题目大意就是给以一段字符xxxxzzz前面x部分是密文z部分是明文,但是我们不知道是从 ...

  10. (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 ...

随机推荐

  1. Python生成器(yield)

    对于调用一个普通的Python函数,一般是从函数的第一行代码开始执行,结束于return语句.异常或者函数所有语句执行完毕.一旦函数将控制权交还给调用者,就意味着全部结束.函数中做的所有工作以及保存在 ...

  2. C - cAPS lOCK

    Problem description wHAT DO WE NEED cAPS LOCK FOR? Caps lock is a computer keyboard key. Pressing it ...

  3. bcg库使用心得两则

    作者:朱金灿 来源:http://blog.csdn.net/clever101 最近帮同事解决了两个BCG库的使用问题,特记录下来. 一是在outlook风格停靠栏上创建对话框的做法.代码如下: C ...

  4. os的进程调度算法(抄袭的)

    package me.letterwish.test; import java.io.BufferedInputStream; import java.io.FileInputStream; impo ...

  5. Yoga710笔记本Win10和Ubuntu系统共存

    联想yoga710默认安装了win10系统,且使用EFI分区格式,安装Ubuntu不是一般的困难,经公司小哥的帮助下,几次终于完成了Ubuntu和Win10 共存. 经过多次安装测试,暂时能运行成功的 ...

  6. 据说现在很缺设计师,阿里云的LOGO是用键盘打出来的……

    今天,阿里云发布了自己的新LOGO,官方的解读是:“[]”这个呢其实是代码中常用的一个符号,代表着计算:中间的“—”则代表流动的数据.在官网等平台上,阿里云新LOGO是动态的,中间的“—”会匀速移动, ...

  7. 整理Webview加载缓慢的解决方案

    1.https://www.cnblogs.com/xinye/p/3144139.html 2.https://www.jianshu.com/p/95d4d73be3d1

  8. /proc目录介绍

    1. /proc目录 Linux 内核提供了一种通过 /proc 文件系统,在运行时访问内核内部数据结构.改变内核设置的机制.proc文件系统是一个伪文件系统,它只存在内存当中,而不占用外存空间.它以 ...

  9. top问题

    1. 从10万个数中找10个最大的数 对于这种题目,最普通的想法是先对这10万个数进行排序,然后再选取数组中前10个数,即为最后的答案,排序算法的时间复杂度不下于O(N lgN).最好的方法是建立一个 ...

  10. Codeforces 902C/901A - Hashing Trees

    传送门:http://codeforces.com/contest/902/problem/C 本题是一个关于“树”的问题. 将一棵高度为h的有根树表示为数列{ai|i=0,1,2,...,h},其中 ...