HDU1358:Period
第一次做KMP。还没有理解透。
在自己写一遍时没有让next[0]初始化为-1。
还有就是next应该是c++中的关键字,提交后编译错误。
From:
http://blog.csdn.net/libin56842/article/details/8498391
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include "ctype.h"
#include "cstdlib"
#include<cmath>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <vector>
using namespace std; char c[1000000];
int ne[1000000]; void cal(){
int i=0,j=-1;
ne[0]=-1;
while(c[i]){
if(c[i]==c[j]||j==-1){
++i;
++j;
ne[i]=j;
}
else{
j=ne[j];
}
}
}
void kmp(){
for(int i=2;c[i-1];++i)
{
int t=i-ne[i];
if(i%t==0 && i/t>1){
printf("%d %d\n",i,i/t);
}
}
}
int main()
{
int i,j,k,n,m,a,b,l;
k=1;
while(cin>>b,b){
scanf("%s",c);
printf("Test case #%d\n",k++);
cal();
kmp();
printf("\n");
} return 0;
}
HDU1358:Period的更多相关文章
- POJ 1961:Period
Period Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 14280 Accepted: 6773 Description F ...
- POJ1961:Period
浅谈\(KMP\):https://www.cnblogs.com/AKMer/p/10438148.html 题目传送门:http://poj.org/problem?id=1961 根据研究发现, ...
- UVALive - 3026:Period
用KMP里面的next数组即可,原理就是next数组的原理 #include<cstdio> #include<cstdlib> #include<algorithm&g ...
- 【暑假】[实用数据结构]UVAlive 3026 Period
UVAlive 3026 Period 题目: Period Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld ...
- R语言学习 第十一篇:日期和时间
R语言的基础包中提供了三种基本类型用于处理日期和时间,Date用于处理日期,它不包括时间和时区信息:POSIXct/POSIXlt用于处理日期和时间,其中包括了日期.时间和时区信息.R内部在存储日期和 ...
- 【源码解读】EOS测试插件:txn_test_gen_plugin.cpp
本文内容本属于<[精解]EOS TPS 多维实测>的内容,但由于在编写时篇幅过长,所以我决定将这一部分单独成文撰写,以便于理解. 关键字:eos, txn_test_gen_plugin, ...
- Java8 Period.between方法坑及注意事项
在使用Java8 新特性中关于Period.between的方法时需注意该方法获取日期的区间问题. @Test public void test1(){ LocalDate from = LocalD ...
- java常用类详细介绍及总结:字符串相关类、日期时间API、比较器接口、System、Math、BigInteger与BigDecimal
一.字符串相关的类 1.String及常用方法 1.1 String的特性 String:字符串,使用一对""引起来表示. String声明为final的,不可被继承 String ...
- Java学习 时间类 Period类与Duration类 / LocalDate类与Instant类 用法详解
前言 java 8 中引入的两个与日期相关的新类:Period 和 Duration.两个类看表示时间量或两个日期之间的差,两者之间的差异为:Period基于日期值,而Duration基于时间值.他们 ...
随机推荐
- Overview and tips for using STM32F303
www.stmcu.org/download/index.php?act=down&id=5264 IntroductionThe purpose of this application no ...
- Cocos2d-html5 笔记2: director
今天看了cocos2d-html5代码里面的Director. 最简单的框架 先抛开cocos2d的框架不说,对于一个游戏来说,基本的逻辑框架还是很简单的,首先初始化的时候注册mouse, touch ...
- shell 编程中使用到得if语句内判断参数
http://blog.chinaunix.net/uid/21411227/cid-63616-list-1.html 1.判断文件类型 –b 当file存在并且是块文件时返回真 -c 当fil ...
- CentOS 6.0 图形(图解)安装教程
http://www.cnblogs.com/vipsoft/archive/2012/04/23/2466062.html
- IPC——命名管道
Linux进程间通信——使用命名管道 转载:http://blog.csdn.net/ljianhui/article/details/10202699 在前一篇文章——Linux进程间通信——使用匿 ...
- highcharts笔记 highcharts学习 highcharts用法
标示线:plotLines : 绘制线:
- Linux服务器集群系统(四)--转
引用地址:http://www.linuxvirtualserver.org/zh/lvs4.html LVS集群的负载调度 章文嵩 (wensong@linux-vs.org) 2002 年 5 月 ...
- LeetCode33 Search in Rotated Sorted Array
题目: Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 ...
- C# 读取与修改配置文件
System.Configuration.ConfigurationSettings.AppSettings["Key"]; 但是现在FrameWork2.0已经明确表示此属性已经 ...
- 1.4.2 solr字段类型--(1.4.2.3)使用货币和汇率
1.4.2 solr字段类型 (1.4.2.1) 字段类型定义和字段类型属性. (1.4.2.2) solr附带的字段类型 (1.4.2.3) 使用货币和汇率 (1.4.2.4) 使用Dates(日期 ...