题目链接:

[kuangbin带你飞]专题十六 KMP & 扩展KMP & Manacher

题目大意:

有一个字符串A,一次次的重写A,会得到一个新的字符串AAAAAAAA…..,现在将这个字符串从中切去一部分得到一个字符串B,例如有一个字符串A=”abcdefg”.,复制几次之后得到abcdefgabcdefgabcdefgabcdefg….,现在切去中间红色的部分,得到字符串B,现在只给出字符串B,求出字符串A的长度

思路:

kmp求最小循环节 = len - nxt[len-1] 或  =len- nxt[len] 根据具体next数组含义而定。

           F - The Minimum Length

Time Limit:1000MS Memory Limit:131072KB 64bit IO Format:%lld &
%llu Submit Status Practice HUST 1010

Description

There is a string A. The length of A is less than 1,000,000. I rewrite
it again and again. Then I got a new string: AAAAAA…… Now I cut it
from two different position and get a new string B. Then, give you the
string B, can you tell me the length of the shortest possible string
A. For example, A=”abcdefg”. I got abcd efgabcdefgabcdefgabcdefg….
Then I cut the red part: efgabcdefgabcde as string B. From B, you
should find out the shortest A.

Input

Multiply Test Cases. For each line there is a string B which contains
only lowercase and uppercase charactors. The length of B is no more
than 1,000,000.

Output

For each line, output an integer, as described above.

Sample Input

bcabcab
efgabcdefgabcde

Sample Output

3
7

/*************************************************************************> File Name: hust_1010.cpp> Author: dulun> Mail: dulun@xiyoulinux.org> Created Time: 2016年03月15日 星期二 21时02分30秒************************************************************************/#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#define LL long long
using namespace std;const int N = 50086;
int nxt[1000006];
char a[1000006];void getnxt(int m)
{int k = 0;for(int i = 1; i < m; i++){while(k && a[i] != a[k]) k = nxt[k-1];if(a[i] == a[k]) k++;nxt[i] = k;}
}int main()
{while(~scanf("%s", a)){memset(nxt, 0, sizeof(nxt));int m = strlen(a);getnxt(m);cout<<m-nxt[strlen(a)-1]<<endl;memset(a, 0, sizeof(a));}return 0;
}

HUST 1010 The Minimum Length相关推荐

  1. kuangbin带你飞专题合集

    题目列表 [kuangbin带你飞]专题一 简单搜索 [kuangbin带你飞]专题二 搜索进阶 [kuangbin带你飞]专题三 Dancing Links [kuangbin带你飞]专题四 最短路 ...

  2. 算法学习经典例题整理

    陆续会对本篇博客进行更新! 搜索:https://vjudge.net/contest/292597 区间DP:https://vjudge.net/contest/293892 树状背包:https ...

  3. kuangbin带你飞 专题1-23 题单

    kuangbin大神,对于打过ACM比赛的ACMer,无人不知无人不晓. 在此,附上vjudge平台上一位大神整理的[kuangbin带你飞]专题目录链接. [kuangbin带你飞专题目录1-23] ...

  4. 第六周 8.23-8.29

    8.23 POJ 3311 Hie with the Pie TSP问题. 先跑一遍Floyd.再状压dp. dp[i][j]表示经过集合i的点最后到达j的最短距离. 转移:取集合i中任意一点j.如果 ...

  5. 老鱼的-kuangbin专题题解

    kuangbin专题问题一览 专题一 简单搜索 POJ 1321 棋盘问题 POJ 2251 Dungeon Master POJ 3278 Catch That Cow POJ 3279 Flipt ...

  6. ValueError: List argument ‘indices‘ to ‘Sparse Concat‘ Op with length 0 shorter than minimum length2

    错误ValueError: List argument 'indices' to 'Sparse Concat' Op with length 0 shorter than minimum lengt ...

  7. 终止linux进程的命令是什么,Linux命令-终止进程命令:kill

    DMSFrame 之SqlCacheDependency(二) 上篇文章介绍的是通知模式的缓存机制,这里介绍的是数据库轮循模式处理,这种模式对SQL2005以下的支持还是比较好的 引擎源码如下: // ...

  8. python题库刷题训练软件_Python基础练习100题 ( 11~ 20)

    刷题继续 上一期和大家分享了前10道题,今天继续来刷11~20 Question 11: Write a program which accepts a sequence of comma separ ...

  9. DPDK l3fwd

    DPDK l3fwd l3fwd负责三层转发,比l2fwd要复杂点. 1 /*- 2 * BSD LICENSE 3 * 4 * Copyright(c) 2010-2014 Intel Corpor ...

最新文章

  1. 聊聊flink的AscendingTimestampExtractor
  2. PHP安装laravel(win+linux)
  3. 关于DubboMain启动的真相
  4. 剑指offer 从头到尾打印链表
  5. oracle让索引失效命令,Oracle中查询时候使index索引失效的限制条件
  6. Machine learning for improved image-based wavefront sensing
  7. 一起谈谈 Java 9 的新特性
  8. 如何使用shell收集linux系统状态,并把结果发给远端服务器
  9. 在写csdn博客时,如何实现用超链接进行页面内跳转?
  10. Atitit 数据库对比较 oracle mysql pgsql 目录 1.1. 跨机器跨库mysql vs pgsql 1 1.2. 动态增加列 pgzhichi 1 1.3. Cte 1 1.4
  11. OpenCV模板匹配(cv2.matchTemplate)
  12. 矢量数据 秦岭淮河_秦岭-淮河一线的大致纬度
  13. 微信小程序:数据传输长度已经超过最大长度 1048576 的错误
  14. 安装semantic segmentation editor
  15. vue Emitter
  16. 考研计算机软件与理论院校排名,计算机软件与理论专业考研院校排名
  17. 在Windows 7镜像中整合“SP2”补丁
  18. Spring Boot面试必问:启动流程
  19. kill命令详解kill -9、kill -15区别
  20. Web自动化之Pytest测试框架

热门文章

  1. 第二次阅读作业--12061161 赵梓皓
  2. bat批处理 安装apk
  3. smart 3D 中的block merge(空三合并)功能详细介绍
  4. Windows 安装dbserver
  5. 步进电机驱动基础2——细分驱动、加减速控制
  6. CAXA CAPP工艺图表2020中文版
  7. 分享一波和黑客斗智斗勇的经历
  8. 大学的多级放大电路,你交给老师了吗?
  9. 详解SEO搜索引擎优化
  10. PowerDVD20中文版|CyberLink PowerDVD Ultra 20中文版 v20.0.2101.62