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)题解
题意:先给你一个密码本,再给你一串字符串,字符串前面是密文,后面是明文(明文可能不完成整),也就是说这个字符串由一个完整的密文和可能不完整的该密文的明文组成,要你找出最短的密文+明文. 思路:我们把字 ...
随机推荐
- MySQL语句整理(二)
数据库操作前的准备 -- 创建数据库 -- create database python_test_1 charset=utf8; -- 使用数据库 -- use python_test_1; -- ...
- Centos7验证Kickstart文件是否完整方法
1.1 功能简介 CentOS 7 包含 ksvalidator 命令行程序,可使用该程序进行确认Kickstart文件.这个工具是 pykickstart 软件包的一部分.要安装pykicks ...
- double工具类
package com.zq.utils; /** * * 经度数字操作类 * * Created by MyEclipse. Author: ChenBin E-mail: chenbin_2008 ...
- 史上更全的 MySQL 高性能优化实战总结!
1 前言 2 优化的哲学 3 优化思路 3.1 优化什么 3.2 优化的范围有哪些 3.3 优化维度 4 优化工具有啥? 4.1 数据库层面 4.2 数据库层面问题解决思路 4.3 系统层面 4.4 ...
- Python知乎热门话题爬取
本例子是参考崔老师的Python3网络爬虫开发实战写的 看网页界面: 热门话题都在 explore-feed feed-item的div里面 源码如下: import requests from py ...
- R语言爬虫:CSS方法与XPath方法对比(表格介绍)
css 选择器与 xpath 用法对比 目标 匹配节点 CSS 3 XPath 所有节点 ~ * //* 查找一级.二级.三级标题节点 <h1>,<h2>,<h3> ...
- python--模块之collection
collection模块: 在内置数据类型(dict.list.set.tuple)的基础上,collections模块还提供了几个额外的数据类型:Counter.deque.defaultdict. ...
- 杭州优步uber司机第二组奖励政策
-8月9日更新- 优步杭州第二组: 定义为激活时间在2015/6/8之后2015/8/3之前的车主(以优步后台数据显示为准) 滴滴快车单单2.5倍,注册地址:http://www.udache.com ...
- 佛山Uber优步司机奖励政策(12月28日到1月3日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- Java Dictionary Example
Dictionary class is the abstract class which is parent of any class which uses the key and value pai ...