当前位置:网站首页>K - Clairewd’s message HDU - 4300 (EXKMP)
K - Clairewd’s message HDU - 4300 (EXKMP)
2022-06-21 21:28:00 【fighting_ yifeng】
K - Clairewd’s message HDU - 4300
The question : Here you are. a-z The decrypted text of is a-z Encrypt the corresponding letters , Then I'll give you a string of numbers , The first half is encrypted and the second half is unencrypted but may not be complete , Let you find the smallest complete string .
analysis : We can parse all the ciphertext , So the front part becomes the decrypted character , Then it becomes exkmp Find the longest prefix match .
#include <iostream>
#include <cstdio>
#include <stack>
#include <cmath>
#include <set>
#include <cstring>
#include <algorithm>
using namespace std;
#define ll long long
const int maxn = 200100;
int t;
char ch[30];
char x[maxn], y[maxn], h[maxn], str[maxn];
int m, n, next1[maxn], extend[maxn];
void pre_EKMP(int m)
{
next1[0] = m;
int j = 0;
while(j + 1 < m && x[j] == x[j + 1]) j++;
next1[1] = j;
int k = 1;
for(int i = 2; i < m; i++)
{
int p = next1[k] + k - 1;
int L = next1[i - k];
if(i + L < p + 1) next1[i] = L;
else{
j = max(0, p - i + 1);
while(i + j < m && x[i + j] == x[j]) j++;
next1[i] = j;
k = i;
}
}
}
void EKMP(int m, int n)
{
pre_EKMP(m);
int j = 0;
while(j < n && j < m && x[j] == y[j]) j++;
extend[0] = j;
int k = 0;
for(int i = 1; i < n; i++){
int p = extend[k] + k - 1;
int L = next1[i - k];
if(i + L < p + 1) extend[i] = L;
else{
j = max(0, p - i + 1);
while(i + j < n && j < m && y[i + j] == x[j]) j++;
extend[i] = j;
k = i;
}
}
}
int main()
{
scanf("%d", &t);
while(t--)
{
scanf("%s%s", &ch, &y);
for(int i = 0; i < 26; i++)
h[ch[i]] = i + 'a';
int len = strlen(y);
memset(x, 0, sizeof(x));
for(int i = 0; i < len; i++)
x[i] = h[y[i]];
EKMP(len, len);
int max1 = len;
for(int i = 0; i < len; i++)
if(i + extend[i] >= len && i >= extend[i])
{
max1 = i;
break;
}
memset(str, 0, sizeof(str));
for(int i = 0; i < max1; i++)
{
str[i] = y[i];
str[i + max1] = h[y[i]];
}
puts(str);
}
return 0;
}
边栏推荐
- 用keil 5编译C51时出现定义未使用的处理方法
- 如何有序协同和管理多个研发项目?
- C语言数组与指针练习题(原题+解析+原码)
- Data visualization tool software
- Libtorch video memory management example
- 【微服务七】Ribbon负载均衡策略之BestAvailableRule源码深度剖析
- DEDECMS织梦后台系统加入自己的栏目菜单
- Modify the UE4 cache path to relieve the pressure on the C disk
- PLC功能块系列之气缸功能块(FB)
- 全新混合架构iFormer!将卷积和最大池化灵活移植到Transformer
猜你喜欢

C语言数组与指针练习题(原题+解析+原码)

Several common device communication protocols in embedded development are summarized

The first in the industry! Krypton app has obtained the authoritative certification of China Network Security Review Technology and Certification Center

一行代码可以做什么?

Unity analog flashlight light source detector, AI attack range detection area, object detection in visual cone, fan-shaped area detection, circular area detection, cone area detection

What plug-ins are available for vscade?

Asynchronous method understanding (demo with code)

With what to save you? My attention

The latest simulation test questions and answers of Henan construction electrician (special construction operation) in 2022

Vscode有什么好用的插件?
随机推荐
Go语言自学系列 | golang标准库encoding/xml
全新混合架构iFormer!将卷积和最大池化灵活移植到Transformer
Idea has this class but can't find it
What is the C language callback function?
用keil 5编译C51时出现定义未使用的处理方法
ASP.Net Core创建Razor页面上传多个文件(缓冲方式)
混合云演习常见案例
[Patents and papers-20]: Operation Guide for electronic information declaration in Nanjing, Jiangsu Province in 2022
pc 电商平台----search模块
数据可视化工具软件
ACM. HJ61 放苹果 ●
关于SQL Server中变量前加上 N与其他使用情况解析
总结了嵌入式开发中几种常见的设备通信协议
VLAN division based on interface: static VLAN [not perfect]
一行代码可以做什么?
Cylinder function block (FB) of PLC function block series
Xshell7+xftp7 free download
如何解决织梦文章列表自动更新点击次数
在程序退出,defer 不执行是为什么
ARP protocol and ARP attack