HUST 1010 The Minimum Length(kmp求周期)
来源:互联网 发布:易语言编程 编辑:程序博客网 时间:2024/05/16 02:33
题意:
有一个字符串A,假设A是“abcdefg”,由A可以重复组成无线长度的AAAAAAA,即“abcdefgabcdefgabcdefg.....”.
从其中截取一段"abcd efgabcdefgabcdefgabcdefg",取红色部分为截取部分,设它为字符串B
现在先给出字符串B,求A最短的长度
分析:
说了这么多废话其实就是求最小循环节=n−nxt[n]
代码:
//// Created by TaoSama on 2015-10-28// Copyright (c) 2015 TaoSama. All rights reserved.////#pragma comment(linker, "/STACK:1024000000,1024000000")#include <algorithm>#include <cctype>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iomanip>#include <iostream>#include <map>#include <queue>#include <string>#include <set>#include <vector>using namespace std;#define pr(x) cout << #x << " = " << x << " "#define prln(x) cout << #x << " = " << x << endlconst int N = 1e6 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;int n, nxt[N];char s[N];void getNxt() { nxt[0] = -1; int i = 0, j = -1; while(i < n) { if(j == -1 || s[i] == s[j]) nxt[++i] = ++j; else j = nxt[j]; }}int main() {#ifdef LOCAL freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);// freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);#endif ios_base::sync_with_stdio(0); while(scanf("%s", s) == 1) { n = strlen(s); getNxt(); printf("%d\n", n - nxt[n]); } return 0;}
0 0
- HUST 1010 The Minimum Length(kmp求周期)
- HUST 1010 The Minimum Length(KMP)
- hust 1010 - The Minimum Length KMP求循环节
- HUST 1010 The Minimum Length (裸KMP)【KMP模板】
- hust 1010 The Minimum Length(KMP)
- HUST 1010-The Minimum Length-KMP
- hust 1010 The Minimum Length (KMP)
- hust 1010 The Minimum Length(KMP求最小循环节)
- HUST 1010 The Minimum Length (kmp求最小循环节)
- HUST - 1010 The Minimum Length(KMP 循环节)
- hust 1010 The Minimum Length
- hust 1010 The Minimum Length
- HUST - 1010 The Minimum Length
- hust 1010 The Minimum Length
- HUST 1010The Minimum Length
- HUST 1010 The Minimum Length
- HUST 1010 The Minimum Length
- HUST 1010 The Minimum Length
- Logistic回归总结
- freqspace
- HDU 2088 &&TOJ 1601. Box of Bricks【水题】好思路
- 硬件加速(HardwareAccelerated)
- 最大子序列和
- HUST 1010 The Minimum Length(kmp求周期)
- <HTML5秘籍>——第四章(构建更好的Web表单)
- IOS股票App,股精灵
- xdcms更换百度编辑器
- 第九周项目2—对称矩阵压缩存储的实现与应用
- 原SLICK3.0 MySQL InnoDB Driver
- 虚幻4 Event、CustomEvent、EventDispatcher
- Haskell经典算法和问题搜集
- AndroidTest