【POJ 2406 Power Strings】
Time Limit: 3000MS
Memory Limit: 65536K
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
- abcd
- aaaa
- ababab
- .
Sample Output
- 1
- 4
- 3
Hint
This problem has huge input, use scanf instead of cin to avoid time limit exceed.
Source
Waterloo local 2002.07.01
题解:
①找出最小循环节————KMP
- #include<stdio.h>
- #include<cstring>
- #define go(i,a,b) for(int i=a;i<=b;i++)
- const int N=4000003;int m,f[N],j;char P[N];
- int main()
- {
- f[0]=f[1]=0;
- while(scanf("%s",P),m=strlen(P),P[0]!='.')
- {
- go(i,1,m-1){j=f[i];while(j&&P[i]!=P[j])j=f[j];f[i+1]=P[i]==P[j]?j+1:0;}
- printf("%d\n",m%(m-f[m])?1:m/(m-f[m]));
- }
- return 0;
- }//Paul_Guderian
镜子里面,像看到人生终点,或许再过上几年
你也有张虚伪的脸,难道我们,是为了这样,才来到这世上……—————《你曾是少年》
【POJ 2406 Power Strings】的更多相关文章
- poj 2406 Power Strings 后缀数组解法
连续重复子串问题 poj 2406 Power Strings http://poj.org/problem?id=2406 问一个串能否写成a^n次方这种形式. 虽然这题用kmp做比较合适,但是我们 ...
- KMP POJ 2406 Power Strings
题目传送门 /* 题意:一个串有字串重复n次产生,求最大的n KMP:nex[]的性质应用,感觉对nex加深了理解 */ /************************************** ...
- poj 2406 Power Strings (kmp 中 next 数组的应用||后缀数组)
http://poj.org/problem?id=2406 Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submiss ...
- POJ 2406 Power Strings (KMP)
Power Strings Time Limit: 3000MSMemory Limit: 65536K Total Submissions: 29663Accepted: 12387 Descrip ...
- poj 2406 Power Strings【最小循环节】
Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 36926 Accepted: 15254 D ...
- poj 2406 Power Strings【字符串+最小循环节的个数】
Po ...
- POJ 2406 Power Strings
F - Power Strings Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u S ...
- KMP + 求最小循环节 --- POJ 2406 Power Strings
Power Strings Problem's Link: http://poj.org/problem?id=2406 Mean: 给你一个字符串,让你求这个字符串最多能够被表示成最小循环节重复多少 ...
- poj 2406:Power Strings(KMP算法,next[]数组的理解)
Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 30069 Accepted: 12553 D ...
随机推荐
- linux文件访问过程和权限
第1章 文件访问过程详解 1.1 文件访问过程 第2章 权限 2.1 对于文件rwx含义 r读取文件内容 w修改文件内容 需要r权限配合 只有w权限的时候,强制保存退出会导致源文件内容丢失 x权限表示 ...
- php 微信公众号图文消息回复的实现 与access_token
//代码如下 <?phpclass IndexAction extends Action { public function __construct(){ } public function i ...
- Windows Server 远程桌面连接不上问题解决
关于Windows Server 远程桌面连接不上的问题需要从服务.端口.防火墙这几方面进行检查: 服务器上需要 开启的服务: - Remote Access Auto Connection Mana ...
- J2EE中getParameter与getAttribute以及对应的EL表达式
摘自http://blog.csdn.net/woshixuye/article/details/8027089 getParameter ① 得到的都是String类型的.如http://name. ...
- PHP.25-TP框架商城应用实例-后台2-商品列表页-搜索、翻页、排序
商品列表页 1.翻页 控制器GoodsController.class.php添加方法lst(),显示列表页 在商品模型GoodsModel.class.php类中添加search方法 /** *实现 ...
- JS是如何计算 1+1=2 的?
身为程序员多年,作者今天突然对这件事感到十分好奇了.我问计算机芸芸部件,1+1究竟是如何计算的,他们都茫然的看着我. 打开谷歌浏览器->Console面板,大脑向双手不停发送生物电信号,肌肉细胞 ...
- Webpack标准配置
let htmlWebpckPlugin= require('html-webpack-plugin');//该组件能将src下面提定的html文件与打包后在js文件打包在一起module.expor ...
- 批量修改Linux文件夹下所有文件大小写
小写转大写: [zengs@SYS SOS]$ for cpplive in *; do mv $cpplive `echo $cpplive|tr [a-z] [A-Z]`; done 大写转小写: ...
- 发送广播重新挂载SD卡,使图库可以及时显示自己保存的图片(无需手机重启)
我们或许经常会遇到这种情况,明明保存了图片,但是当你打开图片时,却没有找到这张图片,手机重启之后才能看到.这是因为SD卡并没有重新挂载,图库也无法把这张图片加载进去,解决这个问题非常简单,只需要我们模 ...
- selenium启动IE浏览器报错:selenium.common.exceptions.WebDriverException: Message: Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones. Enable Protected Mode mu
意思是浏览器的保护模式设置不一致所导致 解决方案-->修改IE设置 将所有区域的保护模式勾选去掉即可