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),布布扣,bubuko.com

时间: 2024-08-26 14:50:24

Period(sdut2476)的相关文章

今天的工作状态,规划未来一段时间内必须完成的事情(Record the working status of today,planning for the next period of time must be completed)

中文: 今天的工作状态,规划未来一段时间内必须完成的事情 待完成功能:(本周完成,不包括modbus传感器,完成之后就不管了) 1.传感器识别功能框架: 根据四个上拉电阻自动识别工作模式:数字型传感器.模拟形传感器.modebus式传感器 2.类似于红外的FD把STM32远程升级功能实现(思考实现方法,如此大的程序,分段存储吗?待处理)3.基于Zigbee的485的透传实现 业余生活: 1.把以上功能实现,ESP8266的AT指令掌握使用,然后基于Linux开发简单的功能(基础) 2.把TI的C

POJ1961 Period

Period Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 18405   Accepted: 8920 Description For each prefix of a given string S with N characters (each character has an ASCII code between 97 and 126, inclusive), we want to know whether the

POJ Period 1961【KMP】

Language: Default Period Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 14658   Accepted: 6968 Description For each prefix of a given string S with N characters (each character has an ASCII code between 97 and 126, inclusive), we want t

poj 1961 Period【求前缀的长度,以及其中最小循环节的循环次数】

Period Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 14653   Accepted: 6965 Description For each prefix of a given string S with N characters (each character has an ASCII code between 97 and 126, inclusive), we want to know whether the

POJ 1961 Period

Period Time Limit: 3000ms Memory Limit: 30000KB This problem will be judged on PKU. Original ID: 196164-bit integer IO format: %lld      Java class name: Main For each prefix of a given string S with N characters (each character has an ASCII code bet

Configure Windows Server 2008 based DHCP database cleanup interval & lease grace period

My Windows Server 2008 based DHCP server related settings: 这里,LeaseExtension设置为10 minutes,意味着默认4个小时的grace period缩短到10分钟.DatabaseCleanupInterval默认为60 minutes,即默认每小时执行一次DHCP database cleanup. Configure Windows Server 2008 based DHCP database cleanup in

POJ——T 1961 Period

http://poj.org/problem?id=1961 Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 18542   Accepted: 9007 Description For each prefix of a given string S with N characters (each character has an ASCII code between 97 and 126, inclusive), we

Period HDU - 1358

For each prefix of a given string S with N characters (each character has an ASCII code between 97 and 126, inclusive), we want to know whether the prefix is a periodic string. That is, for each i (2 <= i <= N) we want to know the largest K > 1 (

hdu_5908_Abelian Period(暴力)

题目链接:hdu_5908_Abelian Period 题意: 给你n个数字,让你找出所有的k,使得把这n个数字分为k分,并且每份的数字种类和个数必须相同 题解: 枚举k,首先k必须是n的约数,然后就能算出每个数字应该出现多少次,O(n)检验即可. 1 #include<bits/stdc++.h> 2 #define F(i,a,b) for(int i=a;i<=b;++i) 3 using namespace std; 4 5 const int N=1e5+7; 6 int t