【题目链接】

点击打开链接

【算法】

KMP

和POJ2406很像

【代码】

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
#define MAXL 1000010 int i,n,TC;
char s[MAXL];
int next[MAXL]; template <typename T> inline void read(T &x) {
int f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) { if (c == '-') f = -f; }
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
} template <typename T> inline void write(T x) {
if (x < ) { putchar('-'); x = -x; }
if (x > ) write(x/);
putchar(x%+'');
} template <typename T> inline void writeln(T x) {
write(x);
puts("");
} inline void getnext() {
int i,pos;
next[] = ;
for (i = ; i <= n; i++) {
pos = next[i-];
while (pos > && s[pos+] != s[i]) pos = next[pos];
if (s[pos+] == s[i]) next[i] = pos + ;
else next[i] = ;
}
} int main() { while (true) {
read(n);
if (!n) return ;
scanf("%s",s+);
getnext();
printf("Test case #%d\n",++TC);
for (i = ; i <= n; i++) {
if (i % (i - next[i]) == && i / (i - next[i]) > ) printf("%d %d\n",i,i/(i-next[i]));
}
puts("");
} return ; }

【POJ 1961】 Period的更多相关文章

  1. 【poj 1961】Period(字符串--KMP 模版题)

    题意:给你一个字符串,求这个字符串到第 i 个字符为止的重复子串的个数. 解法:判断重复子串的语句很重要!!if (p && i%(i-p)==0) printf("%d % ...

  2. bzoj 2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...

  3. 【链表】BZOJ 2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 382  Solved: 111[Submit][S ...

  4. BZOJ2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 284  Solved: 82[Submit][St ...

  5. BZOJ2293: 【POJ Challenge】吉他英雄

    2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 80  Solved: 59[Submit][Stat ...

  6. BZOJ2287: 【POJ Challenge】消失之物

    2287: [POJ Challenge]消失之物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 254  Solved: 140[Submit][S ...

  7. BZOJ2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 126  Solved: 90[Submit][Sta ...

  8. BZOJ2296: 【POJ Challenge】随机种子

    2296: [POJ Challenge]随机种子 Time Limit: 1 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 114  Solv ...

  9. BZOJ2292: 【POJ Challenge 】永远挑战

    2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 513  Solved: 201[Submit][ ...

随机推荐

  1. ngxtop

    http://www.cnblogs.com/felixzh/p/8709201.html

  2. Mac安装IntelliJ IDEA时快捷键冲突设置

    Mac有专门的快捷键,和Linux/Windows的不一样. 下面是发现的一些需要屏蔽的快捷键: 一.搜狗输入法: 暂时没发现有冲突. 二.系统 代码提示:Ctrl+空格(输入法开关) 三.其它 暂无 ...

  3. Android中的多线程编程(一)附源代码

    Android中多线程编程:Handler类.Runnable类.Thread类之概念分析 1.Handler类: Handler是谷歌封装的一种机制:能够用来更新UI以及消息的发送和处理.Handl ...

  4. 数据库系统学习(八)-SQL语言与数据库完整性和安全性

    第八讲 SQL语言与数据库完整性 重难点 数据库完整性的概念 关系数据库 防止和避免数据库中不合理数据的出现 输入错误,操作失误,程序处理错误等 完整性约束条件的一般形式 对O操作集合,当出现A情况时 ...

  5. Win10 LTSB版本安装

    win10 LTSB版本可以看作是 win10的阉割版,没有了几乎用不到还占资源的应用商店.小娜.没有了 EDGE只有IE11....云云 下载地址  https://msdn.itellyou.cn ...

  6. chrome 的onbeforeunload事件没有触发

    onbeforeunload event is not working when user not click inside the body of page 0down votefavorite   ...

  7. 【Discuz】ucenter通讯失败与Discuz的头像无法显示

    假设是Discuz论坛的一些小样式图片.仅仅须要升级一下Discuz论坛的论坛或者,直接把整个网站的css的首域名替换一下.比方将127.0.0.1:8080/..开头的东西全改成127.0.0.1: ...

  8. 关于Memcached的CAS和Set方法造成Socket泄漏的问题

    为了解决多并发下写Memcached的冲突方案,我们项目组引入了CAS机制.类同于Java并发包中的CAS(Compareand set)原子操作,用来处理同一个Item被多个线程更改的并发问题.Me ...

  9. [Unit Testing] Test async function with Jasmine

    Most of time, when we want to test function call inside a promise, we can do: it('Should be async', ...

  10. 查询mysql字段名和字段注释

    select COLUMN_NAME,column_comment from INFORMATION_SCHEMA.Columns where table_name='表名' and table_sc ...