POJ 2406Power Strings(KMP)
其实就是一个简单的kmp应用:
ans = n % (n - f[n]) == 0 ? n / (n - f[n]) : 1
其中f是失配函数
//#pragma comment(linker, "/STACK:1677721600")
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
#define INF 0x3f3f3f3f
#define inf (-((LL)1<<40))
#define lson k<<1, L, (L + R)>>1
#define rson k<<1|1, ((L + R)>>1) + 1, R
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define mem(a, b) memset(a, b, sizeof(a))
#define FIN freopen("in.txt", "r", stdin)
#define FOUT freopen("out.txt", "w", stdout)
#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define dec(i, a, b) for(int i = a; i >= b; i --) template<class T> T MAX(T a, T b) { return a > b ? a : b; }
template<class T> T MIN(T a, T b) { return a < b ? a : b; }
template<class T> T GCD(T a, T b) { return b ? GCD(b, a%b) : a; }
template<class T> T LCM(T a, T b) { return a / GCD(a,b) * b; } //typedef __int64 LL;
typedef long long LL;
const int MAXN = + ;
const int MAXM = ;
const double eps = 1e-;
LL MOD = ; char s[MAXN];
int f[MAXN]; void get_next(int n) {
mem0(f);
rep (i, , n - ) {
int j = f[i];
while(j && s[i] != s[j]) j = f[j];
f[i + ] = s[i] == s[j] ? j + : ;
}
} int main()
{
//FIN;
while(~scanf("%s", s) && s[] != '.') {
int n = strlen(s);
get_next(n);
printf("%d\n", n % (n - f[n]) == ? n / (n - f[n]) : );
}
return ;
}
POJ 2406Power Strings(KMP)的更多相关文章
- poj 2406Power Strings
http://poj.org/problem?id=2406 #include<cstdio> #include<cstring> #include<algorithm& ...
- POJ 1961 Period( KMP )*
Period Time Limit: 3000MSMemory Limit: 30000K Total Submissions: 12089Accepted: 5656 Description For ...
- POJ 2406 Power Strings (KMP)
Power Strings Time Limit: 3000MSMemory Limit: 65536K Total Submissions: 29663Accepted: 12387 Descrip ...
- poj 2406 Power Strings kmp算法
点击打开链接 Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 27368 Accepted: ...
- poj 2406 Power Strings (kmp 中 next 数组的应用||后缀数组)
http://poj.org/problem?id=2406 Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submiss ...
- POJ 2406 - Power Strings - [KMP求最小循环节]
题目链接:http://poj.org/problem?id=2406 Time Limit: 3000MS Memory Limit: 65536K Description Given two st ...
- POJ:2406-Power Strings(寻找字符串循环节)
Power Strings Time Limit: 3000MS Memory Limit: 65536K Description Given two strings a and b we defin ...
- POJ 2406 Power Strings KMP运用题解
本题是计算一个字符串能完整分成多少一模一样的子字符串. 原来是使用KMP的next数组计算出来的,一直都认为是能够利用next数组的.可是自己想了非常久没能这么简洁地总结出来,也仅仅能查查他人代码才恍 ...
- poj 2406 Power Strings(KMP变形)
Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 28102 Accepted: 11755 D ...
随机推荐
- Java transient关键字的理解
transient [ˈtrænziənt] adj. 短暂的; 转瞬即逝的; 临时的 n 临时旅客; 瞬变现象; 候鸟; 1. transient的作用及使用方法 我们都知道一个对象只要 ...
- onsubmit不起作用的原因
使用form表单,添加onsubmit="return check()",来实现提交前进行相关验证功能时,有时会出现js函数不起作用的情况, 此时可以检查相应的js函数check( ...
- ubuntu常用命令解释
1.seq 用于产生一个整数到另一个整数之间所有的整数,如:seq 3 5 输出:3 4 5 注:如果参数为一个整数,则输出1至这个数之间的所有整数 2.tee [-a] file 从标准输入设备读取 ...
- 怎样快速掌握一个用你没学过的框架写的PHP项目?
我的思路一般是先搞定框架的route.也就是说,明白一个请求的url地址是对应的哪个controller处理的,找到controller后,再理解一下它的类库加载方案,也就是说一些辅助类以及自己逻辑类 ...
- 20145221 《Java程序设计》第四周学习总结
20145221 <Java程序设计>第四周学习总结 教材学习内容总结 第六章部分 - 继承与多态 何谓继承 继承 继承是Java程序设计语言面向对象的又一重要体现,允许子类继承父类,避免 ...
- Block作为参数时的使用
Block作为参数使用,常见于各框架之中,比如在封装一个类时,当做什么事情由外界去决定,什么时候调用由自己的类决定时,这时候就需要将block作为参数使用. 下面我们模仿AFNetworking的ma ...
- NOIP 2018 兔纸旅游记
今年是第一次参加tg呢... Day0 早上出发去中旅坐大巴,走有 lz 特色的OI比赛道路. 车上谈笑风生,看 jw 的 GDOI 的小本本. 到动车站取票入站,看 lmh 和 zn 的爱恨情 ...
- Python学习札记(三十九) 面向对象编程 Object Oriented Program 10
参考:使用枚举类 NOTE #!/usr/bin/env python3 from enum import Enum def main(): Mouth = Enum('Mouth', ('Jan', ...
- python swap
swap里面的a,b 不会影响函数作用域外面的变量 java也不可以的吧:python里面没有指针,你可以认为所有的东西都是指向的内容,但是不要试图去改变指针的值 其实我觉得所有的对象都是不可变对象, ...
- QT 正则表达式无效
背景:写了一个判断IP地址合法的正则表达式,并让它应用在输入框中 代码如下 QRegExp rx_ip("^((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}( ...