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 ...
随机推荐
- 居于mtk芯片安卓车机系统具体流程
一:车机系统框架 MCU 功能 电源控制 Radio 控制(RDS) 按键检测(Panel/Remote/SW) 常见信号检查(倒车/大灯/刹车) CAN 模块通讯 ARM- ...
- 【运维技术】node项目使用strongloop进行部署相关教程
node项目使用strongloop进行部署相关教程 安装strongloop 下载安装node 解压到路径完成安装 使用软链方式配置环境变量 添加cnpm的淘宝镜像源 安装node-gyp的模块依赖 ...
- zoj3696Alien's Organ (二项分布,泊松分布求近似值)
/*二项分布即重复n次的伯努利试验,每次发生的概率一样,假设成功的概率是p,那么失败的概率就是1-p: 二项分布的概率公式:试验中发生K次的概率是 P(ξ=K)= C(n,k) * p^k * (1- ...
- Ubuntu安装 jdk.rpm 报错问题解决
报错问题出现原因 第一次使用Ubuntu操作系统,很多命令及软件安装方式与以往使用的Linux操作系统(CentOS)有很大区别.现在总结使用Ubuntu在安装JDK中,遇到的问题及解决方法. roo ...
- 解决com.mongodb.MongoException$CursorNotFound: cursor 0 not found on server
背景 经常需要执行脚本调用Java程序读取mongodb中数据,本来是转为后台进程.偶尔看看日志的简单任务.今天发现程序抛出异常“com.mongodb.MongoException$CursorNo ...
- Python学习札记(三十九) 面向对象编程 Object Oriented Program 10
参考:使用枚举类 NOTE #!/usr/bin/env python3 from enum import Enum def main(): Mouth = Enum('Mouth', ('Jan', ...
- Gym 101243E Cupcakes
http://codeforces.com/gym/101243/attachments 题意: 有n个人,桌子上有k的蛋糕,每个人都有一个值val,表示每次轮到他吃蛋糕时,他可以吃1~val的蛋糕量 ...
- BZOJ 2876 【NOI2012】 骑行川藏
题目链接:骑行川藏 听说这道题需要一些高数知识 于是膜了一发dalao的题解……然后就没了…… 不要吐槽我的精度TAT……eps设太小了就TLE,大了就Wa……我二分的边界是对着数据卡的…… 下面贴代 ...
- 五句话搞定JavaScript作用域【转】
JavaScript的作用域一直以来是前端开发中比较难以理解的知识点,对于JavaScript的作用域主要记住几句话,走遍天下都不怕... 一.“JavaScript中无块级作用域” 在Java或C# ...
- windows java 环境变量配置
第一步 找到系统设置环境变量的位置(windows 10): 控制面板\系统和安全\系统 点击 ‘高级系统设置’ 就可以看到 “环境变量” 了 第二步 设置3个路径 1.path (配置JD ...