HDU4300-Clairewd’s message-KMP
题目链接: 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的更多相关文章
- hdu------(4300)Clairewd’s message(kmp)
Clairewd’s message Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- hdu 4300 Clairewd’s message KMP应用
Clairewd’s message 题意:先一个转换表S,表示第i个拉丁字母转换为s[i],即a -> s[1];(a为明文,s[i]为密文).之后给你一串长度为n<= 100000的前 ...
- HDU-4300 Clairewd’s message
http://acm.hdu.edu.cn/showproblem.php?pid=4300 很难懂题意.... Clairewd’s message Time Limit: 2000/1000 MS ...
- hdu4300 Clairewd’s message【next数组应用】
Clairewd’s message Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- hdu4300 Clairewd’s message
地址:http://acm.hdu.edu.cn/showproblem.php?pid=4300 题目: Clairewd’s message Time Limit: 2000/1000 MS (J ...
- hdu4300 Clairewd’s message 扩展KMP
Clairewd is a member of FBI. After several years concealing in BUPT, she intercepted some important ...
- HDU4300 Clairewd’s message(拓展kmp)
Problem Description Clairewd is a member of FBI. After several years concealing in BUPT, she interce ...
- kuangbin专题十六 KMP&&扩展KMP HDU4300 Clairewd’s message
Clairewd is a member of FBI. After several years concealing in BUPT, she intercepted some important ...
- HDU 4300 Clairewd’s message(KMP+思维)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4300 题目大意:题目大意就是给以一段字符xxxxzzz前面x部分是密文z部分是明文,但是我们不知道是从 ...
- (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 ...
随机推荐
- POJ1915 BFS&双向BFS
俩月前写的普通BFS #include <cstdio> #include <iostream> #include <cstring> #include <q ...
- php中curl的详细解说 【转载】
这几天在帮一些同学处理问题的时候,突然发现这些同学是使用file_get_contents()函数来采集页面内容的,貌似都没有curl的概念亦或是对这种工具特别不敏感, 本文我来给大家详细介绍下cUR ...
- CDN 内容分发网络
第一步,HTML的文件引用:HTML的文件头(也有文件中,文件尾)那边常有其他文件引用,比如CSS以及JS的引用. 就以bootstrap常用的引用来举个栗子你常见的引用可能会是这样的: <he ...
- python--4、装饰器
装饰器(Decorator) 使用场景:为被装饰器装饰的函数增加功能,但又不希望修改函数的定义,即在代码运行期间动态增加功能. 装饰器更多的用于后期功能升级而不是编写新的代码.装饰器不光能装饰函数,也 ...
- 1.0 windows10系统安装步骤(1)
1.0 windows10系统安装步骤(1) 根据自己对笔记本系统的折腾,为了方便他人系统的安装,故总结笔记本系统的安装步骤 目录: 1.0 [windows10系统安装步骤(1)] 2.0 Linu ...
- 【C++】cin、cout的效率比scanf和printf低的解决方法
玩竞赛的同学应该发现了C++中直接调用cout.cin的效率要比printf和scanf的效率要低. 要解决这个问题,只需要在前面加上一句 std::ios::sync_with_stdio(fals ...
- CMMI评估流程
原文链接:http://www.cmmcn.com/new/cmmi-105.html 当前位置:首页 >> CMMI知识库 >> CMMI相关 >> CMMI评估 ...
- C#如何判断操作系统语言版本
using System.Runtime.InteropServices; static void Main(string[] args) { System.Console.WriteLine(Sys ...
- webpack command not found 的意外的坑 - 原因是从node开始
写给自己做个记录: 弄了半天 执行了下面操作 npm install webpack -g 因为小白不懂原理,所以执行了好遍,结果还是如题, webpack command not found 网上搜 ...
- softmax回归---sigmoid(1)
介绍softmax之前先讲讲sigmoid: 逻辑回归模型常用的函数:sigmoid函数(用来做二分类) 表达式:f(x)=L/(1+exp-k(x-x0)) 其图像: 本质:将一个真值映射到(0,1 ...