链接:

https://vjudge.net/problem/HDU-4300

题意:

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.

思路:

题意太难懂. 简单来说, 就是先给一个字符表, 然后给一个由密文和明文组成的字符串,

但是可能不全, 求组成密文和明文最小的长度.

给字符串解密后, 跑扩展KMP, 找一个密文后缀, 明文前缀.

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
//#include <memory.h>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <stack>
#include <string>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <sstream>
#define MINF 0x3f3f3f3f
using namespace std;
typedef long long LL;
const int MAXN = 2e5+10;
const int MOD = 1e4+7; char S[MAXN], a[MAXN], b[MAXN], to[MAXN];
int Next[MAXN], Exten[MAXN]; void GetNext(char *s)
{
int len = strlen(s);
int a = 0, p = 0;
Next[0] = len;
for (int i = 1;i < len;i++)
{
if (i >= p || i+Next[i-a] >= p)
{
if (i >= p)
p = i;
while (p < len && s[p] == s[p-i])
p++;
Next[i] = p-i;
a = i;
}
else
Next[i] = Next[i-a];
}
} void ExKmp(char *s, char *t)
{
int len = strlen(s);
int a = 0, p = 0;
GetNext(t);
for (int i = 0;i < len;i++)
{
if (i >= p || i + Next[i-a] >= p)
{
if (i >= p)
p = i;
while (p < len && s[p] == t[p-i])
p++;
Exten[i] = p-i;
a = i;
}
else
Exten[i] = Next[i-a];
} } int main()
{
int t;
scanf("%d", &t);
while (t--)
{
scanf("%s", S);
scanf("%s", a);
int lens = strlen(S), lena = strlen(a);
for (int i = 0;i < lens;i++)
to[S[i]-'a'] = 'a'+i;
for (int i = 0;i < lena;i++)
b[i] = to[a[i]-'a'];
b[lena] = 0;
ExKmp(a, b);
int len = strlen(a);
int p = len;
for (int i = 0;i < len;i++)
{
if (i+Exten[i] >= len && i >= Exten[i])
{
p = i;
break;
}
}
a[p] = 0;
strcpy(b, a);
for (int i = 0;i < p;i++)
b[p+i] = to[b[i]-'a'];
b[2*p] = 0;
printf("%s\n", b);
} return 0;
}

HDU-4300-Clairewd's message(扩展KMP)的更多相关文章

  1. hdu 4300 Clairewd’s message(扩展kmp)

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

  2. hdu 4300 Clairewd’s message(kmp/扩展kmp)

    题意:真难懂.. 给出26个英文字母的加密表,明文中的'a'会转为加密表中的第一个字母,'b'转为第二个,...依次类推. 然后第二行是一个字符串(str1),形式是密文+明文,其中密文一定完整,而明 ...

  3. HDU 4300 Clairewd's message ( 拓展KMP )

    题意 : 给你一个包含26个小写字母的明文密文转换信息字符串str,第一个表示'a'对应的密文是str[0].'b'对应str[1]……以此类推.接下来一行给你一个另一个字符串,这个字符串由密文+明文 ...

  4. hdu 4300 Clairewd’s message KMP应用

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

  5. HDU - 4300 Clairewd’s message (拓展kmp)

    HDU - 4300 题意:这个题目好难读懂,,先给你一个字母的转换表,然后给你一个字符串密文+明文,密文一定是全的,但明文不一定是全的,求最短的密文和解密后的明文: 题解:由于密文一定是全的,所以他 ...

  6. hdu4300 Clairewd’s message 扩展KMP

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

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

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

  8. hdu 4300 Clairewd’s message(具体解释,扩展KMP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4300 Problem Description Clairewd is a member of FBI. ...

  9. HDU 4300 Clairewd’s message(扩展KMP)

    思路:extend[i]表示原串以第i開始与模式串的前缀的最长匹配.经过O(n)的枚举,我们能够得到,若extend[i]+i=len且i>=extend[i]时,表示t即为该点之前的串,c即为 ...

  10. HDU 4300 Clairewd’s message(扩展KMP)题解

    题意:先给你一个密码本,再给你一串字符串,字符串前面是密文,后面是明文(明文可能不完成整),也就是说这个字符串由一个完整的密文和可能不完整的该密文的明文组成,要你找出最短的密文+明文. 思路:我们把字 ...

随机推荐

  1. [loj#2005][SDOI2017]相关分析 _线段树

    「SDOI2017」相关分析 题目链接:https://loj.ac/problem/2005 题解: 把上面的式子拆掉,把下面的式子拆掉. 发现所有的东西都能用线段树暴力维护. 代码: #inclu ...

  2. libmkl 学习笔记

    libmkl 学习笔记 1.libkml下载地址为: https://github.com/libkml/libkml/releases 这里下载1.3.0版本 2.编译与安装 mkdir build ...

  3. ES-基本概念

    目录: 1.  ElasticSearch是什么 2. 基本概念 3. 几个关键词   正文: 1.  ElasticSearch是什么     ElasticSearch是一个基于Lucene的搜索 ...

  4. gin框架博客实战教程2019web页面开发go语言实战博客开发

    视频教程: https://www.bilibili.com/video/av73698322?t=2400&p=5 资料下载地址(含数据库和main.go和controller里的代码) 注 ...

  5. DRF cbv源码分析 restful规范10条 drf:APIView的源码 Request的源码 postman的安装和使用

    CBV 执行流程 路由配置:url(r'^test/',views.Test.as_view()),  --> 根据路由匹配,一旦成功,会执行后面函数(request) --> 本质就是执 ...

  6. Python 基础(十七)--序列化

    pickle模快 pickle.dumps():可将特有数据类型的转换为bytes类型 pickle.loads():将bytes类型转化回来 >>> import pickle & ...

  7. day05-06

    day05 上传下载 下载工具软件: lrzsz 安装方法: yum install lrzsz -y 下载命令就是sz 上传命令就是rz 下载到widow实列 sz 文件名 上传到linux 执行r ...

  8. day03-04

    光驱 历史的东西 远程管理卡 ​ 它的作用是通过网络远程(异地)开关服务器,并可以查看服务器开关的过程等信息,早期(2010年以前),服务器托管在IDC机房,出问题,还得跑机房或者请机房的人管理,有了 ...

  9. Lua 截取字符串(截取utf-8格式字符串)

    对utf-8完全没概念的可以看看我上一篇随笔:简单说说utf-8编码格式 另外,还要知道string.sub 和 string.byte 的用法. 先上完整代码: local StringHelper ...

  10. Laravel使用whereHas进行过滤不符合条件的预加载with数据

    问题描述:目前有用户表,文章表,文章评论表,收藏表.我需要获我的收藏文章列表(可以被搜索,通过分类,文章标题等),通过收藏预加载with文章表,文章评论表,文章用户表 解决办法:通过whereHas限 ...