POJ 2406 Power Strings(kmp)

西门子 S7-200 SMART 系列六:手把手教你配置S7-200 SMART Modbus RTU Modbus 是公开通信协议,其最简单的串行通信部分仅规定了在串行线路的基本数据传输格式。Modbus 具有两种串行传输模式,ASCII 和 RTU,它们定义了数据如何打包、解码的不同方式。支持 Modbus 协议的设备一般都支持 RTU 格式。 阅读详情
Power Strings
Time Limit: 3000MS Memory Limit: 65536K
Total Submissions: 47749 Accepted: 19903

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


题意: 给出一个字符串,找出其循环节并判断其循环了几次。


本题考查了对next数组的理解             若有不懂请戳这里

    


不难发现,如果字符串长度len可以整除next[ len ]的话,循环节长度就等于 len - next[ len ] ,否则循环节长度就等于1。


#include <stdio.h>
#include <string.h>
using namespace std;

const int N = 1e6 + 10;
char a[N];
int nex[N];

void get_nex(int l){
    int i = 0, j = -1;
    nex[0] = -1;
    while(i < l){
        if(j == -1 || a[i] == a[j]){
            i++, j++;
            nex[i] = j;
        }
        else j = nex[j];
    }
}

int main(){
    while(scanf("%s", &a), a[0] != '.'){
        int l = strlen(a);
        get_nex(l);
        if(!(l%(l-nex[l]))) printf("%d\n", l/(l-nex[l]));
        else printf("1\n");
    }
}





1、CUDA 编程基础 GPU计算的发展历程与重要性。首先回顾了计算机技术的发展,特别是摩尔定律的影响,强调了计算能力的快速提升。然而,随着晶体管尺寸的缩小和频率的停滞,单线程性能增长放缓。为了继续提升性能,多核处理器开始普及,促使软件开发者开始考虑并行计算。介绍了延迟导向设计和吞吐量导向设计的概念,CPU和GPU分别代表了这两种设计方法。GPU是吞吐量导向的,拥有众多弱小的ALU,通过流水线处理提高算术吞吐量。GPU的成功在于其高并行性和高吞吐量,以及能够分摊高昂的固定成本的大量销售额。 阅读详情

相关推荐

Intouch实时报警

Intouch实时报警功能的相关设置

weixin_41571357的博客 4202

POJ 2406--Power Strings(kmp算法)

题意:给定一规模为1e6的字符串,

dingzuoer的专栏 570

倒立摆入门详解+pid调参

倒立摆制作全过程 最近在练习pid的控制算法,就选用了2013年的电子设计国赛题目:倒立摆 。 首先给你们看看我的成果 注意哦:倒立摆不是靠上面黄色的传感器保持平衡的,而是通过下面的电机左右扭动使得摆杆不掉下来,难度可不小了。 材料准备 1.机械部分 如图所示选好电机和角位移传感器进行组装就好了,这个部分是我直接网上购买的,如果要自己装也是可以的,不过会比较麻烦,结构差不多的。 2.主控部分 这个部分的话完全是我自己设计的,作用和网上买的一样,因为网上买的话太贵了,有需要的话可以联系我,有pcb文件

small_po_kid的博客 2万+

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

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

[SZU_Crayon] 729

[亚信线上教学] AX58100: EtherCAT从站设备仿真功能设计教学

什么情况需要开启EtherCAT从站设备仿真功能呢? 一般来说, 当EtherCAT从站产品,不需要使用额外的微控制器介入,或使用不具备EtherCAT从站通讯协议栈的微控制器一同协作的情况下,就必须开启EtherCAT从站设备仿真功能,这样EtherCAT主站才能够正常设置从站设备的工作状态. 亚信AX58100 EtherCAT从站控制芯片的优点 AX58100 EtherCAT从站控制器, 集成2个百兆以太网Phis, 并支持一些额外的控制接口, 例如脉冲宽度调变, 增量, 霍尔编码器, .

allanchou1的专栏 7422

基于Playwright的雪球网股票情绪数据自动化采集实战

网络爬虫是自动化获取互联网公开数据的关键技术,其核心原理在于模拟浏览器行为或直接发送HTTP请求以解析网页内容。在金融科技与量化分析领域,实时、稳定的数据源具有极高的技术价值,能够为市场情绪分析、因子挖掘提供基础。面对采用动态加载、复杂反爬机制的现代单页应用,传统的请求库与Selenium方案在稳定性与隐蔽性上面临挑战。本文聚焦于利用Playwright这一现代浏览器自动化工具,通过模拟真实用户交互、监听网络请求,构建一个能够稳定采集雪球社区实时讨论热度的解决方案。该方案不仅解决了动态内容渲染问题,还通过请

weixin_42529328的博客 585

poj 2406 Power Strings 【KMP + 技巧处理】

欢迎关注__Xiong的博客: http://blog.youkuaiyun.com/acmore_xiong?viewmode= Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 38054   Accepted: 15753 传送门

Fighting! 2449

069、PCIE属性字段:缓存、顺序与安全

上个月调试一块自研的PCIE采集卡,遇到了一个诡异的问题:主机通过DMA从设备读取图像数据,大部分帧正常,但偶尔会出现局部数据错位,像是缓存没刷干净。用逻辑分析仪抓链路层报文,发现TLP(事务层包)本身完好,但内存中的数据就是不对。排查三天后,终于锁定在设备端TLP的**属性字段(Attribute Field)**配置上——那几位看似不起眼的缓存、顺序控制位,差点让项目延期。今天我们就拆解PCIE事务头中的这个关键区域,看看它如何影响系统性能与数据安全。

z534437748的博客 50

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

2026 年 AI 大模型资讯深度研究报告 / 2026 年 3 月 11 日

2026 年已成为 AI 大模型发展的关键拐点年。从 2023 年 ChatGPT 开启的技术奇点,历经多模态突破、推理能力崛起,至 2025 年形成产业爆发态势,AI 大模型正从"技术验证期"迈向"产业落地期"。核心发现技术突破: OpenAI 于 2026 年 3 月 6 日发布 GPT-5.4,首次实现原生计算机操控能力,在 OSWorld 桌面操控测试中以 75% 成功率超越人类 (72.4%),标志着 AI 从"对话工具"向"自主数字员工"的时代跃迁市场格局。

AI天才研究院 785

Python爬虫:抓取专利数据并分析专利趋势

本文展示了如何使用 Python 爬虫技术抓取中国专利数据,并对数据进行了清洗、分析和趋势预测。通过分析专利数据,企业和科研机构可以了解行业的技术发展趋势,进行技术创新战略规划。未来,我们可以进一步扩展爬虫的功能,抓取更多专利数据,增加多维度的数据分析,如技术领域、地域分布等。同时,可以尝试使用深度学习模型(如 LSTM)进行时间序列预测,以获得更准确的专利趋势预测。

2201_76125261的博客 1787

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

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

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

大太阳 633

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

【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

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

poj2406 Power Strings 简单KMP

poj2406

Forjames的栏目 490

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

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

poj2406-Power Strings(kmp)

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

lvy的专栏 464

poj 2406 Power Strings(未优化的KMP)

2406 Power Strings(未优化的KMP)

PKU_ZZY的博客 877

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)

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

题目: Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 41220   Accepted: 17140 Description Given two strings a and b we define a*b to be thei

CFhM_R's Blog 531

【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

poj 2406 Power Strings (KMp)

题意:给一个字符串S长度不超过10^6,求最大的n使得S由n个相同的字符串a连接而成,如:"ababab"则由n=3个"ab"连接而成,"aaaa"由n=4个"a"连接而成,"abcd"则由n=1个"abcd"连接而成。 定理:假设S的长度为len,则S存在循环子串,当且仅当,len可以被len - next[len]整除,最短循环子串为S[len - next[len]] 例子证

张小V 400

poj 2406 Power Strings 【kmp】

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

每个人的心中都藏着一个衰小孩儿 470

【POJ 2406】 Power Strings(KMP求循环节)

【POJ 2406】 Power Strings(KMP求循环节) Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 40536   Accepted: 16862 Description Given two strings a and b we define a*b

ACMer' 1955
上一篇: CF#348 A. Mafia(二分,思维)
下一篇: HDU 5253 连接的管道(最小生成树)
信鸦
博客等级 码龄10年 10粉丝 133原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值