POJ 2406 Power Strings(kmp)

数学建模 种群竞争模型 学习笔记 模型背景 应用场景 种群竞争模型 例如 s1=0.5,则表示对于供养甲的资源来讲,单位数量的乙的消耗为单位数量的甲的0.5倍,即表示乙对于该资源的占有能力是甲的0.5倍(即竞争力弱) 仿真结果及分析 (1)设置自然增长率 r1=r2=1 (2)改变自然增长率 r1=r2=0.3 (3)修改甲和乙的最大容量 n1=10000, n2=100 (4)修改甲和乙的初始数量 x1=10, x... 阅读详情

Language:
Power Strings
Time Limit: 3000MS Memory Limit: 65536K
Total Submissions: 33335 Accepted: 13852

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



求一个串的最小周期


对于一个串,如果abcdabc 那么next[len]=3,那么len-next【len】就大于len/2,那么len%(len-next[len])!=0;而对于一个周期串ababab next[len]=4,此时len-next[len]应该等于

最小串的长度,所以是不是有最小周期就可以用len%(len-next[len])是否为0来判断,(个人理解,如有错,请想告)



#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>

#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1)

#define eps 1e-8
using namespace std;
#define N 100005

char a[N];
int len,next[N];

void getfail(char *a)
{
	 int i,j;
	 len=strlen(a);
	 i=0;j=-1;
	 next[0]=-1;
	 while(i<len)
	 {
	 	if(j==-1||a[i]==a[j])
		{
			 i++;
			 j++;
			 next[i]=j;
		}
		else
			j=next[j];
	 }
}

int main()
{
	int i,j;
	while(scanf("%s",a))
	{
		if(a[0]=='.') break;
		getfail(a);
		int ans=len%(len-next[len]);
		if(ans==0)
			printf("%d\n",len/(len-next[len]));
		else
			printf("1\n");
	}
	return 0;
}







EUV光源技术路线深度解析 EUV光刻技术的关键瓶颈在于13.5纳米光源的稳定高效获取。主流技术路线从DPP放电等离子体发展为LPP激光等离子体方案,后者通过激光轰击锡液滴实现更高功率输出。新出现的LDP技术综合激光预热与放电优势,虽功率扩展性有限,但为光源技术提供了有益补充。目前LPP仍是唯一通过量产验证的方案,而LDP可能作为过渡技术应用于特定场景。EUV光源的发展实质是能量转化效率与系统可靠性的持续优化过程,各种技术路线的探索共同推动着这一核心工艺的进步。 阅读详情

相关推荐

类银河恶魔城游戏开发学习笔记(0)

解决B站搬运【Unity教程】从0编程制作类银河恶魔城游戏P37中moveState和idleState循环切换的问题

Gellar的博客 1447

CF - 223 - B. Two Strings

题意:给出两个由小写字母组成的字符串s和t(长度都不超过2*10^5),问能否用t作为s的子序列把s的每一个字母都用过(s中的字母可以用多次)。 题目链接:http://codeforces.com/problemset/problem/223/B ——>>第一步:从左往右扫描s,记录s[i]能匹配到t的最右位置L[i]; 第二步:从右往左扫描s,记录s[i]能匹配到的t最左位置R[i];

无节操 1303

Cisco Secure ACS 5.8.0.32 安装 + Crack 教程

在ESXi 6.7 上经历过无数次的安装尝试测试了各种兼容版本都没有安装成功,记最后一次安装成功的过程.

Junior's Blog 3536

Power Strings_poj2406_kmp

DescriptionGiven 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

olahiuj的博客 489

point transformer v3结构

分割结构: embedding->enc->dec embedding->enc0->enc1->enc2->enc3->enc4->dec3->dec2->dec1->dec0 embedding ->block0->block1 ->dow->block0->block1 ->dow->block0->block1 ->dow->block0->block1-&gt

weixin_45625419的博客 581

51单片机超声波测距数码管显示并报警(Proteus 仿真)

HC-SR04超声波 实物图 使用方法 1、给TRIG端口至少10us 的高电平信号 2、模块自动发送 8 个 40khz 的方波,自动检测是否有信号返回 3、有信号返回,ECHO端口会输出一个高电平,高电平持续的时间就是超声波从发射到返回的时间 计算的话这里就不考虑温度的影响直接用声速340m/s Proteus仿真 HC-SR04可以用Proteus中的SRF04代替 下面附上代码 ...

m0_46254883的博客 1万+

POJ 2405 KMP next数组的运用 ʕ •ᴥ•ʔ

Power Strings   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, expone...

henucm的博客 362

mongodb在游戏开发领域的优势

目前游戏服务器使用mysql作为数据库的较多,然而,使用mongodb来作为存储层,在某些方面比mysql更为方便和适合。

littleschemer的博客 1698

POJ 2406 Power Strings kmp求循环结

Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 37505   Accepted: 15492 Description Given two strings a and b we define a*b to be their concatena

巧克力华夫脆 435

如何设计提示词来减少 AI 的幻觉问题?

如何设计提示词来减少 AI 的幻觉问题?

我哎GIS博客 2468

7.29华为OD机试真题 新系统 - 能量对撞 (Java/Py/C/C++/Js/Go)

7.29华为OD机试真题 新系统 - 能量对撞 (Java/Py/C/C++/Js/Go)

算法大师! 1315

Power Strings(求循环次数最多的循环节 kmp)

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-...

caowenbo2311694605的博客 475

数仓建模—数据治理框架选型

全名主要亮点覆盖面最广:从数据治理、架构、质量、安全到元数据、主数据、数据仓库等等,几乎所有数据管理主题都能在DMBOK里找到相应章节。概念权威统一:帮助组织建立通用术语和知识基础,减少“部门之间说法不一致”的沟通成本。适用场景:如果你所在公司(或团队)正准备系统梳理数据管理的方方面面,DMBOK是一份非常全面的指导手册,尤其适合培养新人或为整个组织统一认知。需要注意:DMBOK偏“知识指引”,不直接提供成熟度模型或实施路线图。想要落地,还需要结合其他评估模型或项目管理方法。小案例举例:某。

2401_84052244的博客 4743

KMP-(POJ 2406)Power Strings[字符串乘方]

KMP-(POJ 2406)Power Strings[字符串乘方] 题目链接:Power Strings 思路:最小循环节 看到乘方,很明显是求给定字符串由它的最小循环子串循环得到的次数 那就是求出NEXT数组,再而求出最小循环节长度:Len-NEXT[Len] 有三种情况,分两类 ①给定字符串循环子串是其本身:乘方等于1         a.NEXT[Len]...

[SZU_Crayon] 728

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

poj 2406 Power Strings kmp

Language: Default Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 30779   Accepted: 12821 Description Given two strings a and b we define a

AC_kereo的专栏 971

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

POJ 2406 Power Strings(KMP)

题目链接:http://poj.org/problem?id=2406 解题思路: 题目的意思是寻找给出的字符串的最小循环节对应的循环次数 利用KMP的性质,若0~i是循环的,那么fail[i+1]=循环节长度*(循环次数-1) 参考 https://blog.youkuaiyun.com/weixin_43768644/article/details/90108511 代码: #inclu...

shadiao.的博客 208

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

poj 2406 Power Strings(kmp)

http://poj.org/problem?id=2406 Power Strings 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 w

大太阳 632

【KMP】 poj2406 Power Strings

Power Strings http://poj.org/problem?id=2406 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

Ted's 游乐园 753

poj2406 Power Strings(kmp)

poj2406 Power Strings(kmp) 给出一个字符串,问这个字符串是一个字符串重复几次。要求最大化重复次数。 若当前字符串为S,用kmp匹配'\0'+S和S即可。 #include <cstdio> #include <cstring> using namespace std; const int maxn=2e6+5; char s1[ma...

111

poj2406 Power Strings 简单KMP

poj2406

Forjames的栏目 490

poj 2406 Power Strings(未优化的KMP)

2406 Power Strings(未优化的KMP)

PKU_ZZY的博客 876

poj2406 Power Strings kmp

一个字符串可以由他的一个子串a重复n次得到,现在给一个长度不大于10^6的字符串,求最长n。       跟白书上的period (训练之南P213,例13)基本一样甚至还简单一点。核心就是利用KMP中的失配函数求最短循环节。可以得到对于字符串的第i位,若有i % (i-f[i])==0,则f[i]到i之间的部分及为这个串的最短循环节,具体画个图,或者参考白书上的图,很容易就能看出来。    

Broken Wings 822

poj 2406 Power Strings kmp算法

点击打开链接 Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 27368   Accepted: 11454 Description Given two strings a and b we define a*b to be

云淡风清 852

POJ-2406 Power Strings (KMP)

Problem 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, exp...

李先生家的猫的博客 472

poj2406-Power Strings(kmp)

用kmp来做的,把整个串看成一个匹配串,然后求它的next[i],如果strlen(str)-next[strlen(str)]的值被strlen(str)整除,那么说明它找到了循环节,否则就。原理证明其实用四个字就可以说明:错位相等。原理证明 这道活用了kmp的题目相当有意思!

lvy的专栏 463

【POJ2406】【KMP】Power Strings

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, expone...

Gregory99174的博客 146
上一篇: codeforce D. Password
下一篇: Hot Days Codeforces Round #132 (Div. 2) D(贪心)
左眼皮跳跳~
博客等级 码龄13年 17粉丝 400原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值