G - Power Strings
2024-08-29 20:07:50
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.
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
using namespace std;
#define MAXN 1000001
typedef long long LL;
/*
给定一个串,找最短循环节
*/
char s[MAXN];
int Next[MAXN];
void kmp_pre(int m)
{
int j,k;
j = ;k = Next[] = -;
while(j<m)
{
if(k==-||s[j]==s[k])
Next[++j] = ++k;
else
k = Next[k];
}
}
int main()
{
while(scanf("%s",s))
{
if(s[]=='.') break;
int l = strlen(s);
kmp_pre(l);
int ans = l - Next[l];
if(l%ans==)
printf("%d\n",l/ans);
else
printf("1\n");
}
}
最新文章
- Tomcat7.0安装配置
- 配置 Windows 下的 nodejs C++ 模块编译环境
- 今天早上刚刚碰到的一个问题oracle数据归档已满,只能进行内部连接,ORA-00257 archiver error. 错误的处理方法
- sqlserver 读取xml 字符串方法
- Java学习第一天
- javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure 解决方案
- SMON功能(一):清理临时段
- 使用APUE(UNIX高级编程)源代码
- <;转Tanky Woo>; 字典树
- Apache服务器安装配置(win版)
- zip &; tar 压缩文件时排除某个文件夹
- 谈谈书本《c#物联网程序设计基础》中的技术瑕疵,如果你将要读本书,请进来看看!
- Python总结(一)
- 全卷积网络 FCN 详解
- Leetcode: The Maze(Unsolved locked problem)
- scrapy 快速入门
- 【学习总结】 小白CS成长之路
- kudu的读取数据流程
- Maven &; Gradle 如何从中央仓库下载Jar包
- Android 下载zip压缩文件并解压
热门文章
- Appium + python -yaml配置文件
- Windows(7/8/10)搭建kibana 6.x版本(elasticsearch的可视化服务)
- Linux 本命令 基本上用到的命令-自己留着用
- 【POJ3280/洛谷2890】[Usaco2007 Open Gold]Cheapest Palindrome(动态规划)
- 327 Count of Range Sum 区间和计数
- 检查阿里云ssl证书到期情况
- 浅谈Java中的hashcode方法以及equals方法
- C#入门经典 Chapter4 流程控制
- mysql自动增长的有关问题,怎么恢复从1开始
- vm装xp安装成功后进入不了系统