HUST 1010 The Minimum Length
题目链接:
[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相关推荐
- kuangbin带你飞专题合集
题目列表 [kuangbin带你飞]专题一 简单搜索 [kuangbin带你飞]专题二 搜索进阶 [kuangbin带你飞]专题三 Dancing Links [kuangbin带你飞]专题四 最短路 ...
- 算法学习经典例题整理
陆续会对本篇博客进行更新! 搜索:https://vjudge.net/contest/292597 区间DP:https://vjudge.net/contest/293892 树状背包:https ...
- kuangbin带你飞 专题1-23 题单
kuangbin大神,对于打过ACM比赛的ACMer,无人不知无人不晓. 在此,附上vjudge平台上一位大神整理的[kuangbin带你飞]专题目录链接. [kuangbin带你飞专题目录1-23] ...
- 第六周 8.23-8.29
8.23 POJ 3311 Hie with the Pie TSP问题. 先跑一遍Floyd.再状压dp. dp[i][j]表示经过集合i的点最后到达j的最短距离. 转移:取集合i中任意一点j.如果 ...
- 老鱼的-kuangbin专题题解
kuangbin专题问题一览 专题一 简单搜索 POJ 1321 棋盘问题 POJ 2251 Dungeon Master POJ 3278 Catch That Cow POJ 3279 Flipt ...
- 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 ...
- 终止linux进程的命令是什么,Linux命令-终止进程命令:kill
DMSFrame 之SqlCacheDependency(二) 上篇文章介绍的是通知模式的缓存机制,这里介绍的是数据库轮循模式处理,这种模式对SQL2005以下的支持还是比较好的 引擎源码如下: // ...
- python题库刷题训练软件_Python基础练习100题 ( 11~ 20)
刷题继续 上一期和大家分享了前10道题,今天继续来刷11~20 Question 11: Write a program which accepts a sequence of comma separ ...
- DPDK l3fwd
DPDK l3fwd l3fwd负责三层转发,比l2fwd要复杂点. 1 /*- 2 * BSD LICENSE 3 * 4 * Copyright(c) 2010-2014 Intel Corpor ...
最新文章
- 聊聊flink的AscendingTimestampExtractor
- PHP安装laravel(win+linux)
- 关于DubboMain启动的真相
- 剑指offer 从头到尾打印链表
- oracle让索引失效命令,Oracle中查询时候使index索引失效的限制条件
- Machine learning for improved image-based wavefront sensing
- 一起谈谈 Java 9 的新特性
- 如何使用shell收集linux系统状态,并把结果发给远端服务器
- 在写csdn博客时,如何实现用超链接进行页面内跳转?
- Atitit 数据库对比较 oracle mysql pgsql 目录 1.1. 跨机器跨库mysql vs pgsql	1 1.2. 动态增加列 pgzhichi	1 1.3. Cte	1 1.4
- OpenCV模板匹配(cv2.matchTemplate)
- 矢量数据 秦岭淮河_秦岭-淮河一线的大致纬度
- 微信小程序:数据传输长度已经超过最大长度 1048576 的错误
- 安装semantic segmentation editor
- vue Emitter
- 考研计算机软件与理论院校排名,计算机软件与理论专业考研院校排名
- 在Windows 7镜像中整合“SP2”补丁
- Spring Boot面试必问:启动流程
- kill命令详解kill -9、kill -15区别
- Web自动化之Pytest测试框架