当前位置:网站首页>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时出现定义未使用的处理方法

【微服务七】Ribbon负载均衡策略之BestAvailableRule源码深度剖析

AXI_Bus_Matrix_4x4 设计 - 逻辑设计部分
![[Patents and papers-19]: Notice on electronic information application of Nanjing City, Jiangsu Province in 2022 (medium and advanced)](/img/a5/47c1b189cfd4bee6edb68c266a3816.png)
[Patents and papers-19]: Notice on electronic information application of Nanjing City, Jiangsu Province in 2022 (medium and advanced)

ctfshow 105-127

Asynchronous method understanding (demo with code)

科研漫畫 | 看圖可以學腦電,來試試?

Introduction to high performance intranet DNS system
![[专利与论文-20]:江苏省南京市2022年电子信息申报操作指南](/img/bb/313f4a9f9c03ab2e9dfe0e8846831e.png)
[专利与论文-20]:江苏省南京市2022年电子信息申报操作指南

拖延患者自救指南|“我有不拖延的100种借口,却不愿意跨出一步”
随机推荐
Product innovation - an innovative social app that returns to real life
Citus 11 for Postgres 完全开源,可从任何节点查询(Citus 官方博客)
On the charm of code language
DEDECMS织梦后台邮箱验证发送邮件配置教程
Common cases of hybrid cloud exercises
十一、美化界面
PowerPoint 教程,如何在 PowerPoint 中将幻灯片整理成组?
[Patents and papers-19]: Notice on electronic information application of Nanjing City, Jiangsu Province in 2022 (medium and advanced)
The first in the industry! Krypton app has obtained the authoritative certification of China Network Security Review Technology and Certification Center
MySQL数据库---存储引擎
Mysql database - storage engine
2022年最新河南建筑施工电工(建筑特种作业)模拟试题及答案
How to solve the problem of automatically updating the click times of weaving dream article list
Go语言自学系列 | golang标准库encoding/xml
matplotlib plt.subplots()详解
Modify the UE4 cache path to relieve the pressure on the C disk
Golang learning notes - pointer
Caricature scientifique | Vous pouvez apprendre l'EEG en regardant les images. Voulez - vous essayer?
11、 Beautify the interface
【物联网开发】正点原子STM32战舰v3+机智云AIoT+APP控制