当前位置:网站首页>K - Clairewd’s message HDU - 4300 (EXKMP)
K - Clairewd’s message HDU - 4300 (EXKMP)
2022-06-21 19:39:00 【fighting_yifeng】
K - Clairewd’s message HDU - 4300
题意:给你a-z的解密文即a-z加密对应的字母,然后给你一串数,前半部分是加密过的后半部分未加密过但可能不完整,让你求最小的完整的字符串。
分析:我们可以将密文全部解析,这样前面部分就变成解密后的字符,接下来就变成了exkmp找到最长前缀匹配。
#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;
}
边栏推荐
- 一行代码可以做什么?
- Data types and usage of mediacodec
- Leecode198 looting
- The final scheme of adding traceid at the C end
- Class loading process of JVM
- [MySQL · water drop plan] the third part - basic concepts of SQL
- Quels sont les conseils que les programmeurs débutants ne connaissent pas?
- Is it true and safe for qiniu to open a securities account? Do you charge for opening an account
- Intersection of vector and plane
- 浅谈代码语言的魅力
猜你喜欢

集群一---LVS负载均衡集群NAT模式及LVS负载均衡实战部署
![[applet] realize applet and background ASP through request Net data JSON transmission (post protocol text + code)](/img/e7/1a270d2aa03f38426bc57bd0ee00b6.png)
[applet] realize applet and background ASP through request Net data JSON transmission (post protocol text + code)

libtorch显存管理示例

NS32F103VBT6软硬件替代STM32F103VBT6

Convert string type to list < integer >

总结了嵌入式开发中几种常见的设备通信协议

Unity 模拟手电筒光源探测器,AI攻击范围检测区域,视锥内检测物体,扇形区域检测,圆形区域检测,圆锥区域检测

MySQL learning (from getting started to mastering 1.2)

Introduction to internet protocol -- five layer model

C语言回调函数到底是怎么回事?
随机推荐
Welcome to the markdown editor
Vector expansion mechanism of STL
Tencent global digital ecology Conference - high speed intelligent computing special session!
高考后网上查询信息,注意防范没有 SSL证书的网站
[OWT] P2P signaling server running
Introduction to internet protocol -- five layer model
2016 ICLR | Adversarial Autoencoders
Class loading process of JVM
【CTF】攻防世界 MISC
Dedecms dream weaving background system adds its own column menu
Mysql database - index
Leecode198 looting
【微服务七】Ribbon负载均衡策略之BestAvailableRule源码深度剖析
What is more advantageous than domestic spot silver?
About n before variables in SQL server and other usage analysis
2022年全国最新消防设施操作员(中级消防设施操作员)模拟题库及答案
Intersection of vector and plane
How functions are declared
MySQL learning (from getting started to mastering 1.2)
MediaCodec的数据类型和使用方式