HDU 4300 Clairewd’s message (next函数的应用)
题意:给你一个明文对密文的字母表,在给你一段截获信息,截获信息前半段是密文,后半段是明文,但不清楚它们的分界点在哪里,密文一定是完整的,明文可能是残缺的,求完整的信息串(即完整的密文+明文串)。
题解:KMP next函数的应用。
#include <cstdio>
#include <cstring>
#include <cstdlib> const int MAXN = ; char table[];
char extable[];
char ori[MAXN];
char aft[MAXN];
int next[MAXN];
int len; void init()
{
for ( int i = ; i < ; ++i )
extable[ table[i]-'a' ] = 'a' + i; len = strlen(ori);
for ( int i = ; i < len/; ++i )
aft[i] = ori[i]; for ( int i = len/; i < len; ++i )
aft[i] = table[ ori[i] - 'a' ]; aft[len] = '\0'; return;
} void getNext( char* s, int* next )
{
int length = len;
int i = , j = -;
next[] = -;
while ( i < length )
{
if ( j == - || s[i] == s[j] )
{
++i, ++j;
next[i] = j;
}
else j = next[j];
}
} int main()
{
int T;
scanf( "%d", &T );
while ( T-- )
{
scanf( "%s", table );
scanf( "%s", ori );
init();
getNext( aft, next ); int ans = len;
//printf("next[%d] = %d\n", ans, next[ans] );
while ( next[ans] > len/ ) ans = next[ans];
ans = len - next[ans];
//printf( "ans = %d\n", ans );
for ( int i = ; i < ans; ++i )
printf( "%c", ori[i] );
for ( int i = ; i < ans; ++i )
printf( "%c", extable[ ori[i] - 'a' ] );
puts("");
}
return ;
}
HDU 4300 Clairewd’s message (next函数的应用)的更多相关文章
- 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 字符串哈希
Clairewd’s message Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- HDU - 4300 Clairewd’s message (拓展kmp)
HDU - 4300 题意:这个题目好难读懂,,先给你一个字母的转换表,然后给你一个字符串密文+明文,密文一定是全的,但明文不一定是全的,求最短的密文和解密后的明文: 题解:由于密文一定是全的,所以他 ...
- hdu 4300 Clairewd’s message(具体解释,扩展KMP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4300 Problem Description Clairewd is a member of FBI. ...
- hdu 4300 Clairewd’s message(扩展kmp)
Problem Description Clairewd is a member of FBI. After several years concealing in BUPT, she interce ...
- HDU 4300 Clairewd’s message(KMP+思维)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4300 题目大意:题目大意就是给以一段字符xxxxzzz前面x部分是密文z部分是明文,但是我们不知道是从 ...
- 【HDU 4300 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)
思路:extend[i]表示原串以第i開始与模式串的前缀的最长匹配.经过O(n)的枚举,我们能够得到,若extend[i]+i=len且i>=extend[i]时,表示t即为该点之前的串,c即为 ...
- HDU 4300 Clairewd’s message(扩展KMP)题解
题意:先给你一个密码本,再给你一串字符串,字符串前面是密文,后面是明文(明文可能不完成整),也就是说这个字符串由一个完整的密文和可能不完整的该密文的明文组成,要你找出最短的密文+明文. 思路:我们把字 ...
随机推荐
- 浅析Vue原理(部分源码解析)
响应式 Object.defineProperty Object.defineProperty(obj, prop, descriptor) // 对象.属性.描述符 Object.definePro ...
- springboot(2.0以上) --数据源切换时报错
在进行数据源切换时spring.datasource.type类型根据源码所给的默认值修改后依然报错 先看源码:标色部分 , 就是springboot所给的数据源 , 正常来说只要在配置文件中修改 ...
- js实现QQ、微信、新浪微博分享功能
微信分享需要手机扫描二维码,需要对url进行编码.在https协议下,扫描二维码时,浏览器打不开可能时安全证书导致的. var shareModel = { /** * 分享QQ好友 * @param ...
- 一、Vue项目构建
Attention:以下内容为Mac机上运行,windows可能有所偏差- Step1 打开终端,键入npm install -g vue-cli,使用vue-cli脚手架搭建vue项目能省很多事儿- ...
- 虚拟机下linux 系统网卡配置、固定IP地址
1.进入该目录下修改内容 vi /etc/sysconfig/network-scripts/ ifcfg-eth0 TYPE=Ethernet BOOTPROTO=static DEF ...
- .net第三方数据库物理卡号同步功能实现
本地数据库用的是Oracle,第三方数据库是SQL Server,连接字符串保存在web.config里面. 第三方数据库为增量,每次读取要记录读取的最大位置.我是保存在本地txt文件里面. //保存 ...
- Python学习 :集合
集合 Set 集合的创建 集合的创建只有一种方式 集合中的元素必须是不可变的数据类型 集合是无序的,可以通过 for 循环来遍历或者迭代器进行筛选 s=set('xiaoming') s1=['ale ...
- ruby中的字符串分隔符--split
当字符串是以“:”隔开时,可以这样写: column = str.split(/:/) 这样,column就是字符串每栏的值所构成的数组. eg: str = "Ruby in a shel ...
- Python学习:5.函数以及基础语句
函数 一.创建函数 Python的函数的学习是Python基础的一个重要部分,函数可以重复利用,减少代码量,接下来我们就学习一下如何创建一个函数,以及函数的使用. 1.创建一个函数的基本格式 def ...
- STM32_2 简单分析startup函数
;******************** (C) COPYRIGHT STMicroelectronics ******************** ;* File Name : startup_s ...