题意:给你一个明文对密文的字母表,在给你一段截获信息,截获信息前半段是密文,后半段是明文,但不清楚它们的分界点在哪里,密文一定是完整的,明文可能是残缺的,求完整的信息串(即完整的密文+明文串)。

题解:KMP next函数的应用。

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <cstdlib>
  4.  
  5. const int MAXN = ;
  6.  
  7. char table[];
  8. char extable[];
  9. char ori[MAXN];
  10. char aft[MAXN];
  11. int next[MAXN];
  12. int len;
  13.  
  14. void init()
  15. {
  16. for ( int i = ; i < ; ++i )
  17. extable[ table[i]-'a' ] = 'a' + i;
  18.  
  19. len = strlen(ori);
  20. for ( int i = ; i < len/; ++i )
  21. aft[i] = ori[i];
  22.  
  23. for ( int i = len/; i < len; ++i )
  24. aft[i] = table[ ori[i] - 'a' ];
  25.  
  26. aft[len] = '\0';
  27.  
  28. return;
  29. }
  30.  
  31. void getNext( char* s, int* next )
  32. {
  33. int length = len;
  34. int i = , j = -;
  35. next[] = -;
  36. while ( i < length )
  37. {
  38. if ( j == - || s[i] == s[j] )
  39. {
  40. ++i, ++j;
  41. next[i] = j;
  42. }
  43. else j = next[j];
  44. }
  45. }
  46.  
  47. int main()
  48. {
  49. int T;
  50. scanf( "%d", &T );
  51. while ( T-- )
  52. {
  53. scanf( "%s", table );
  54. scanf( "%s", ori );
  55. init();
  56. getNext( aft, next );
  57.  
  58. int ans = len;
  59. //printf("next[%d] = %d\n", ans, next[ans] );
  60. while ( next[ans] > len/ ) ans = next[ans];
  61. ans = len - next[ans];
  62. //printf( "ans = %d\n", ans );
  63. for ( int i = ; i < ans; ++i )
  64. printf( "%c", ori[i] );
  65. for ( int i = ; i < ans; ++i )
  66. printf( "%c", extable[ ori[i] - 'a' ] );
  67. puts("");
  68. }
  69. return ;
  70. }

HDU 4300 Clairewd’s message (next函数的应用)的更多相关文章

  1. hdu 4300 Clairewd’s message KMP应用

    Clairewd’s message 题意:先一个转换表S,表示第i个拉丁字母转换为s[i],即a -> s[1];(a为明文,s[i]为密文).之后给你一串长度为n<= 100000的前 ...

  2. hdu 4300 Clairewd’s message 字符串哈希

    Clairewd’s message Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  3. HDU - 4300 Clairewd’s message (拓展kmp)

    HDU - 4300 题意:这个题目好难读懂,,先给你一个字母的转换表,然后给你一个字符串密文+明文,密文一定是全的,但明文不一定是全的,求最短的密文和解密后的明文: 题解:由于密文一定是全的,所以他 ...

  4. hdu 4300 Clairewd’s message(具体解释,扩展KMP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4300 Problem Description Clairewd is a member of FBI. ...

  5. hdu 4300 Clairewd’s message(扩展kmp)

    Problem Description Clairewd is a member of FBI. After several years concealing in BUPT, she interce ...

  6. HDU 4300 Clairewd’s message(KMP+思维)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4300 题目大意:题目大意就是给以一段字符xxxxzzz前面x部分是密文z部分是明文,但是我们不知道是从 ...

  7. 【HDU 4300 Clairewd’s message】

    Clairewd is a member of FBI. After several years concealing in BUPT, she intercepted some important ...

  8. HDU 4300 Clairewd’s message(扩展KMP)

    思路:extend[i]表示原串以第i開始与模式串的前缀的最长匹配.经过O(n)的枚举,我们能够得到,若extend[i]+i=len且i>=extend[i]时,表示t即为该点之前的串,c即为 ...

  9. HDU 4300 Clairewd’s message(扩展KMP)题解

    题意:先给你一个密码本,再给你一串字符串,字符串前面是密文,后面是明文(明文可能不完成整),也就是说这个字符串由一个完整的密文和可能不完整的该密文的明文组成,要你找出最短的密文+明文. 思路:我们把字 ...

随机推荐

  1. MySQL语句整理(二)

    数据库操作前的准备 -- 创建数据库 -- create database python_test_1 charset=utf8; -- 使用数据库 -- use python_test_1; -- ...

  2. Centos7验证Kickstart文件是否完整方法

    1.1    功能简介 CentOS 7 包含 ksvalidator 命令行程序,可使用该程序进行确认Kickstart文件.这个工具是 pykickstart 软件包的一部分.要安装pykicks ...

  3. double工具类

    package com.zq.utils; /** * * 经度数字操作类 * * Created by MyEclipse. Author: ChenBin E-mail: chenbin_2008 ...

  4. 史上更全的 MySQL 高性能优化实战总结!

    1 前言 2 优化的哲学 3 优化思路 3.1 优化什么 3.2 优化的范围有哪些 3.3 优化维度 4 优化工具有啥? 4.1 数据库层面 4.2 数据库层面问题解决思路 4.3 系统层面 4.4 ...

  5. Python知乎热门话题爬取

    本例子是参考崔老师的Python3网络爬虫开发实战写的 看网页界面: 热门话题都在 explore-feed feed-item的div里面 源码如下: import requests from py ...

  6. R语言爬虫:CSS方法与XPath方法对比(表格介绍)

    css 选择器与 xpath 用法对比 目标 匹配节点 CSS 3 XPath 所有节点 ~ * //* 查找一级.二级.三级标题节点 <h1>,<h2>,<h3> ...

  7. python--模块之collection

    collection模块: 在内置数据类型(dict.list.set.tuple)的基础上,collections模块还提供了几个额外的数据类型:Counter.deque.defaultdict. ...

  8. 杭州优步uber司机第二组奖励政策

    -8月9日更新- 优步杭州第二组: 定义为激活时间在2015/6/8之后2015/8/3之前的车主(以优步后台数据显示为准) 滴滴快车单单2.5倍,注册地址:http://www.udache.com ...

  9. 佛山Uber优步司机奖励政策(12月28日到1月3日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  10. Java Dictionary Example

    Dictionary class is the abstract class which is parent of any class which uses the key and value pai ...