Periodic Strings UVA
来源:互联网 发布:便宜域名注册 编辑:程序博客网 时间:2024/05/16 05:43
https://vjudge.net/contest/192890#problem/B
题意: 问你循环节长度。
思路:还是nex数组的简单应用,首先要是有循环节的话就直接输出len-nex[len],没有就输出len 水题(天天也就能刷刷水题了 T _ T)..
上代码吧:
#include <stdio.h>#include <string.h>char ch[1000];int nex[1000];void pre_kmp(){memset(nex,0,sizeof(nex));int len = strlen(ch) , i = 0 , k = -1;nex[0] = -1;while(i<len){if(k == -1 ||ch[i] == ch[k]){i++,k++;nex[i] = k;}else {k = nex[k];}}}int main(){int t;scanf("%d",&t);while(t--){scanf("%s",ch);int len = strlen(ch);pre_kmp();if(len % (len - nex[len])==0){printf("%d\n",len-nex[len]);}else {printf("%d\n",len);}if(t){puts("");}}}/*2abcabcabcHoHoHo*/
阅读全文
0 0
- UVA 455 - Periodic Strings
- UVa 455 - Periodic Strings
- UVa 455 - Periodic Strings
- UVa 455 - Periodic Strings
- UVa 455 Periodic Strings
- UVa - 455 Periodic Strings
- UVa 455 Periodic Strings
- UVa 455 - Periodic Strings
- Uva 455-periodic strings
- Uva 455-periodic strings
- UVa-455Periodic Strings
- 【Uva 455】 Periodic Strings
- UVA - 455 Periodic Strings
- UVa 455 - Periodic Strings
- Uva - 455 - Periodic Strings
- UVA - 455 Periodic Strings
- UVa 455 - Periodic Strings
- UVa 455 - Periodic Strings
- HDU
- 如何在 Ubuntu 上用 Yocto 创建你自己的嵌入式 Linux 发行版
- 多选框
- 3011: [Usaco2012 Dec]Running Away From the Barn
- 将二叉树拆成链表-LintCode
- Periodic Strings UVA
- 信息学奥赛一本通(C++版) 第一部分 C++语言 第一章 C++语言入门
- java面试题之集合框架
- Cg Programming/Unity/Two-Sided Smooth Surfaces双面平滑曲面
- [CQOI2007]涂色paint dp(区间)
- bnu 10790 Periodic Table of Elements(模拟)
- socket中的read返回0
- 纪念一次搭建git服务器所踩的坑,最详细全部过程 | ssh | git | centos
- 《Machine Learning》第三讲 逻辑回归(LR)