hdu 1358 Period
来源:互联网 发布:域名代理商源码 编辑:程序博客网 时间:2024/05/16 19:31
http://acm.hdu.edu.cn/showproblem.php?pid=1358
寻找循环性前缀,利用KMP周期性。
AC代码:
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>using namespace std;const int MAX = 1000010;char str[MAX];int next[MAX];void getnext(){ int i=0, j=-1,n=strlen(str); next[0] = -1; while(i < n){ if(j == -1 || str[i] == str[j]){ i++,j++; next[i] = j; } else j = next[j]; }}int main(){ int n,t = 0; while(scanf("%d",&n) == 1){ if(!n) break; scanf("%s",str); getnext(); printf("Test case #%d\n",++t); for(int i=1; i<=n; i++){ int count = i - next[i]; if(count != i && i % count == 0) printf("%d %d\n",i,i/count); } printf("\n"); } //system("pause"); return 0;}
0 0
- HDU 1358 Period (KMP)
- HDU 1358 Period
- hdu 1358 Period
- hdu 1358 Period
- hdu 1358 Period
- HDU 1358 Period KMP
- hdu 1358 Period
- hdu 1358 Period KMP
- hdu 1358 Period(KMP)
- HDU 1358 Period KMP
- hdu 1358 Period
- hdu 1358 Period
- 【HDU】1358 Period KMP
- HDU - 1358 Period
- HDU 1358 Period (KMP)
- HDU 1358 Period
- hdu 1358 Period
- HDU 1358 Period
- git tag 使用方法总结
- std_msgs::UInt8MultiArray发布数组
- kickstart配置文件详解
- 有哪些实用的计算机相关技能,可以在一天内学会 (有个SVN和GIT的)
- glib配置错误(gtk-doc、libtool、automaker、autoconf的安装)
- hdu 1358 Period
- 类模板
- 【First step to the last one】JAVA多线程整理(一)
- 示波器探头×1和×10的意义
- 802.11速率计算
- javascript中的正则表达式(来自W3C)
- 给Eclipse提速的7个技巧
- Ryu eventlet学习总结
- kali-linux VPN设置