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基于时间值.他们 ...
随机推荐
- START167 AND BOOT167
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka10535.html C166: START167 AND BOO ...
- App Submission Issues
查看原文: http://leancodingnow.com/app-submission-issues/ I bet many iOS developers are busy submitting ...
- windows7下实现局域网内文件共享
1.右击桌面网络----属性----更改高级共享设置 (注释:查看当前网络 比如:家庭网络.公共网络 等!) "我这里为公共网络" 2.选择 公共网络---选择以下选项:启动网络发 ...
- Linux 卸载Oracle 11G
卸载oracle11G数据 1.使用SQL*PLUS停止数据库[oracle@OracleTest oracle]$ sqlplus /nologSQL> connect / as sysdba ...
- C# WinForm使用Aspose.Cells.dll 导出导入Excel/Doc 完整实例教程
1.添加引用: Aspose.Cells.dll(我们就叫工具包吧,可以从网上下载.关于它的操作我在“Aspose.Cells操作说明 中文版 下载 Aspose C# 导出Excel 实例”一文中的 ...
- [转载]GMT地形数据总结
[转载]GMT地形数据总结 原文地址:GMT地形数据总结作者:Jason 转载:http://seisman.info/gmt-topo-grid-datas.html 目前接触到的地形数 ...
- Linq lamda表达式Single和First方法
让我们来看看如何对一个整数数组使用 Single 操作符.这个整数数组的每个元素代表 2 的 1 到 10 次方.先创建此数组,然后使用 Single 操作符来检索满足 Linq Lambda表达 ...
- linxu,window系统
window下:net start VMwareHostdVMAuthdServiceVMUSBArbService"VMware NAT Service"VMnetDHCP #启 ...
- __KERNEL__ macro
转载:http://blog.csdn.net/kasalyn/article/details/17097639 The __KERNEL__ macro is defined because the ...
- LeetCode18 4Sum
题意: Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = ...