hdu1358 Period kmp求循环节
链接
http://acm.hdu.edu.cn/showproblem.php?pid=1358
思路
当初shenben学长暑假讲过,当初太笨了,noip前几天才理解过来、、
我也没啥好说的
代码
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int N=1e6+7;
int n,len,fail[N];
char s[N];
void get_fail() {
int p=0;
for(int i=2;i<=len;++i) {
while(s[p+1]!=s[i]&&p>0) p=fail[p];
if(s[p+1]==s[i]) p++;
fail[i]=p;
}
}
int AK;
void solve() {
memset(fail,0,sizeof(fail));
get_fail();
printf("Test case #%d\n",++AK);
for(int i=2;i<=len;++i) {
if(fail[i]&&i%(i-fail[i])==0) {
printf("%d %d\n",i,i/(i-fail[i]));
}
}
puts("");
}
int main() {
while(233) {
scanf("%d",&len);
if(!len) break;
scanf("%s",s+1);
solve();
}
return 0;
}
hdu1358 Period kmp求循环节的更多相关文章
- HDU1358 Period —— KMP 最小循环节
题目链接:https://vjudge.net/problem/HDU-1358 Period Time Limit: 2000/1000 MS (Java/Others) Memory Lim ...
- hdu 3374 String Problem (字符串最小最大表示 + KMP求循环节)
Problem - 3374 KMP求循环节. http://www.cnblogs.com/wuyiqi/archive/2012/01/06/2314078.html 循环节推导的证明相当 ...
- UVA 12012 Detection of Extraterrestrial(KMP求循环节)
题目描述 E.T. Inc. employs Maryanna as alien signal researcher. To identify possible alien signals and b ...
- 17999 Light-bot 模拟 + kmp求循环节
http://acm.scau.edu.cn:8000/uoj/mainMenu.html 17999 Light-bot 时间限制:1000MS 内存限制:65535K 提交次数:0 通过次数:0 ...
- 【HDU 3746】Simpsons’ Hidden Talents(KMP求循环节)
求next数组,(一般有两种,求循环节用的见代码)求出循环节的长度. #include <cstdio> #define N 100005 int n,next[N]; char s[N] ...
- hdu3746 kmp求循环节
CC always becomes very depressed at the end of this month, he has checked his credit card yesterday, ...
- HDU3746(KMP求循环节)
Cyclic Nacklace Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- hdu 3746 kmp求循环节
题意就是将所给的字符串变成多个完整的循环(至少两个),然后给出最少需要添加的字符数.
- (KMP 求循环节)The Minimum Length
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=70325#problem/F The Minimum Length Time Limit: ...
随机推荐
- TP父类及模板继承
一.TP父类方法继承 session用法 用登录页面做例子 <?php namespace Home\Controller; use Think\Controller; class LoginC ...
- PE结构图示
- Mysql常规优化
一.SQL语句优化 (1)使用limit对查询结果的记录进行限定(2)避免select *,将需要查找的字段列出来(3)使用连接(join)来代替子查询(4)拆分大的delete或insert语句 二 ...
- keras如何求分类问题中的准确率和召回率
https://www.zhihu.com/question/53294625 由于要用keras做一个多分类的问题,评价标准采用precision,recall,和f1_score:但是keras中 ...
- SLAM学习笔记
ORB_SLAM2源码: 获得旋转矩阵,来自这里:http://www.cnblogs.com/shang-slam/p/6406584.html 关于Covisibility图来自:http://b ...
- Spring 无缝整合 quartz
关键步骤: 1. 配置 SchedulerFactoryBean <bean class="org.springframework.scheduling.quartz.Schedule ...
- org/hibernate/ejb/HibernatePersistence
java.lang.NoClassDefFoundError: org/hibernate/ejb/HibernatePersistence 缺少依赖包:hibernate-entitymanager ...
- 监控MySQL主从脚本
示例一: cat check_mysql_health #!/bin/sh slave_is=($(mysql -S /tmp/mysql3307.sock -uroot -e "show ...
- 自写Jquery插件 Combobox
原创文章,转载请注明出处,https://www.cnblogs.com/GaoAnLee/p/9092421.html 上效果 html <span id='combobox' class=' ...
- ubuntu重启+sublime快捷键
sudo reboot Sublime常用快捷键: 掌握基本的代码编辑器的快捷键,能让你打码更有效率,刚开始可能不大记得住,多敲几次就能熟悉并使用它 精华键 : Ctrl+Shift+P:打开命令面板 ...