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 ...
随机推荐
- 如何正确从windows系统(自己电脑)远程访问Linux系统(他人电脑)的mysql数据库(图文详解)
这里,需要Linux系统开了root用户,我这给root用户密码为root. 同时,在mysql -uroot -proot执行进去之后 update user setHost='%' whe ...
- js动态追加的元素如何触发事件
一般通过js或者jQuery动态添加的元素标签,通过该元素标签.class.id触发事件,是无效的.如下所示: <body> <input type="text" ...
- 重装系统后快速安装.NET 3.5
每一次重装系统(Windows 8.1 和Windows 10)之后,最让我头疼的一件事就是配置把一大堆软件装上了.通常我会装好SQL Server之后,把电脑放在工作组安装Visual Studio ...
- CORS 和 JSONP
跨域资源共享(CORS) 它允许浏览器向跨源服务器,发出XMLHttpRequest请求,从而克服了AJAX只能同源使用的限制. CORS(Cross-Origin Resource Sharing) ...
- 子线程更新UI
https://www.cnblogs.com/joy99/p/6121280.html
- javascript中计算点击多少次
点击事件:onclick <!DOCTYPE html> <html lang="en"> <head> <meta charset=&q ...
- IOS 监控网络变化案例源码
随着移动网络升级:2G->3G->4G甚至相传正在研发的5G,网络速度是越来越快,但这流量也像流水一般哗哗的溜走. 网上不是流传一个段子:睡觉忘记关流量,第二天房子就归移动了! 这固然是一 ...
- openMSP430之openmsp430-loader
openmsp430-loader This simple program allows the user to load the openMSP430 program memory with an ...
- dubbo之本地存根
本地存根 远程服务后,客户端通常只剩下接口,而实现全在服务器端,但提供方有些时候想在客户端也执行部分逻辑,比如:做 ThreadLocal 缓存,提前验证参数,调用失败后伪造容错数据等等,此时就需要在 ...
- 使用脚本卸载.net framework for mac
官方只提供了安装包,没提供卸载