poj 2406 Power Strings
来源:互联网 发布:网络侦探龙帝 编辑:程序博客网 时间:2024/06/06 06:37
Power Strings
Time Limit: 3000MS Memory Limit: 65536KTotal Submissions: 33636 Accepted: 13973
Description
Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc" and b = "def" then a*b = "abcdef". If we think of concatenation as multiplication, exponentiation by a non-negative integer is defined in the normal way: a^0 = "" (the empty string) and a^(n+1) = a*(a^n).
Input
Each test case is a line of input representing s, a string of printable characters. The length of s will be at least 1 and will not exceed 1 million characters. A line containing a period follows the last test case.
Output
For each s you should print the largest n such that s = a^n for some string a.
Sample Input
abcdaaaaababab.
Sample Output
143
题目大意:给出一个字符串,求这个串是有几个子串构成的思路:用KMP算法中的next数组,这个字符串的next数组里边,字符串的总长度len减去字符串最后一个字符的下一个字符(就是'\0')所对应的next值next[len],就是子串的长度,next数组的值是根据字符串本身用一定规则得出,next数组存放的是如果匹配不成功要跳转到的位置,这个很巧妙,kmp算法,好好看看。2014,12,5
#include<stdio.h>#include<string.h>char x[1100000];int next[1100000];void getnext(char s[]){int len1,i,j;len1=strlen(s);i=0;j=-1;next[i]=j;while(i<len1){if(j==-1||s[i]==s[j]){++i;++j;next[i]=j;}else j=next[j];}}int main(){int t,len;while(scanf("%s",x)){getnext(x);if(x[0]=='.') break;else {len=strlen(x);t=len-next[len];if(len%t==0)printf("%d\n",len/t);else printf("1\n");}}return 0;}
0 0
- poj 2406 "Power Strings"
- poj 2406 Power Strings
- POJ-2406 Power Strings
- POJ 2406 Power Strings
- poj 2406 Power Strings
- POJ:2406 Power Strings
- poj 2406 Power Strings
- poj 2406 Power Strings
- poj 2406 Power Strings
- POJ 2406 Power Strings
- POJ 2406 - Power Strings
- poj 2406 Power Strings
- poj 2406 Power Strings
- POJ 2406 Power Strings
- POJ 2406 Power Strings
- POJ 2406 Power Strings
- poj 2406 Power Strings
- POJ 2406 Power Strings
- Android_基础知识_01_异步任务AsyncTask
- pull解析技术
- 内存泄漏检测工具
- 耦合与内聚
- 从头开始学java--抽象类&接口
- poj 2406 Power Strings
- Android自定义控件——开源组件SlidingMenu的项目集成
- 计算文件的md5
- 模式识别知识结构图(思维导图)
- struts2上传图片
- CopyOnWriteArraySet
- Topcoder SRM144 div2 1100
- Dynamic Programming 0-1 knapsacks 动态规划之01背包问题
- 微软宣布.NET开发环境将开源 支持三大操作系统