Period(sdut2476)
[题目大意]:给定一个字符串,求到哪一位时的字串是前几位循环组成的,并求出循环次数。
思路:求每个前缀的最小循环周:从i到n枚举len,如果len%(len-next[len])==0,则这个前缀是由循环节组成的,且循环次数为len/(len-next[len])//len为当前i的值,next[len]为当前j的值。
#include <stdio.h> #include <string.h> #include <stdlib.h> char a[1000001]; int next[1000001]; int n; void Getnext() {
int i=0;
int j=-1;
next[0]=-1;
while(i<n) {
if(j==-1||a[i]==a[j])
{
i++;
j++;
next[i]=j;
if(i%(i-next[i])==0&&i/(i-next[i])>1) {
printf("%d %d\n",i,i/(i-next[i]));
}
}
else j=next[j];
} } int main() {
int k=0;
while(scanf("%d",&n)!=EOF)
{
k++;
if(n==0) break;
getchar();
for(int i=0;i<n;i++)
scanf("%c",&a[i]);
printf("Test case #%d\n",k);
Getnext();
printf("\n");
}
return 0; }
Period(sdut2476)的更多相关文章
- TCP Provider The semaphore timeout period has expired
我们一数据库服务器上有个作业最近几天偶尔会遇到下面错误(敏感信息已做处理),主要是报"TCP Provider: The semaphore timeout period has expir ...
- SSRS 2008 R2 错误:Timeout expired. The timeout period
今天遇到了Reporting Services(SQL SERVER 2008 R2)的报表执行异常情况,报表加载数据很长时间都没有响应,最后报"An error occurred with ...
- Clock Skew , Clock Uncertainty和 Period
本文将介绍FPGA中和时钟有关的相关概念,阅读本文前需要对时序收敛的基本概念和建立.保持关系有一定了解,这些内容可以在时序收敛:基本概念,建立时间和保持时间(setup time 和 hold tim ...
- HDU 5908 Abelian Period(暴力+想法题)
传送门 Description Let S be a number string, and occ(S,x) means the times that number x occurs in S. i. ...
- Match:Period(POJ 1961)
Period 题目大意:给定一个字符串,要你找到前缀重复了多少次 思路,就是kmp的next数组的简单应用,不要修正next的距离就好了,直接就可以跳转了 PS:喝了点酒用递归实现除法和取余了...结 ...
- cargo failed to finish deploying within the timeout period [120000]
cargo插件,报错:failed to finish deploying within the timeout period [120000] 解决方法:配置timeout为0 <plugin ...
- Date get period
/** * get period for last year * @param time * @return */ public static DatePeriodDTO getLastYear(lo ...
- Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
今天碰到了一个查询异常问题,上网查了一下,感谢原创和译者 如果你使用的数据库连接类是 the Data Access Application Blocks "SqlHelper" ...
- POJ 1961 Period( KMP )*
Period Time Limit: 3000MSMemory Limit: 30000K Total Submissions: 12089Accepted: 5656 Description For ...
随机推荐
- <转>机器学习系列(9)_机器学习算法一览(附Python和R代码)
转自http://blog.csdn.net/han_xiaoyang/article/details/51191386 – 谷歌的无人车和机器人得到了很多关注,但我们真正的未来却在于能够使电脑变得更 ...
- IOS设计模式第四篇之装饰设计模式的类别设计模式
装饰设计模式 装饰设计模式动态的添加行为和责任向一个对象而不修改他的任何代码.他是你子类化修改类的行为用通过另一个对象的包装的代替方法. 在Objective-c里面有很多这种设计模式的实现,像cat ...
- openlayers中利用vector实现marker的方式
项目需要一个小型的gis.openlayers,geoserver,postgres组合是比较好的选择. openlayers的marker层好像不支持拖动操作.通过研究api发现,可以利用vecto ...
- 【大数据系列】hadoop2.0中的jobtracker和tasktracker哪里去了
低版本的hadoop下MapReduce处理流程 1.首先用户程序(JobClient)提交了一个job,job的信息会发送到Job Tracker,Job Tracker是Map-reduce框架的 ...
- html2canvas - 项目中遇到的那些坑点汇总(更新中...)
截图模糊 原理就是讲canvas画布的width和height放大两倍. 后来学习canvas的时候,才了解到这种写法不同于css的宽高设置, 因为css里的只是展示画布显示的大小,不像这样是c ...
- css方法 - 移动端h5在iphonex的适配
@media only screen and (device-width:375px) and (device-height:812px) and (-webkit-device-pixel-rati ...
- 自己实现atoi
bool myatoi(const char *s,int &num) { cout<<(&s)<<endl; num=; while (*s) { ') { ...
- Elasticsearch学习之深入搜索三 --- best fields策略
1. 为帖子数据增加content字段 POST /forum/article/_bulk { "} } { "doc" : {"content" : ...
- 题目1446:Head of a Gang(并查集操作)
题目链接:http://ac.jobdu.com/problem.php?pid=1446 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...
- Mac下门罗币矿工样本分析
背景 今天遇到一个JSONRPC的告警,怀疑挖矿木马,IOC是132.148.245.101,无其他信息,随即google一波. 查询网络 遇到了,主动下载样本分析,下载地址:http://rjj.q ...