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 ...
随机推荐
- 1 :2 Strust2—Demo
=============================================================== Demo基础包:
- Redis 监控方案
一.概述 近些天,遇到Redis监控的应用场景,从网上搜罗了一些文章,做了整理. 二.工具列表 2.1 redis-faina 见参考文章1 2.2 redis-live 见参考文章1 2.3 red ...
- Vue学习笔记之Nodejs入门
0x00 前言 打开Nodejs英文网:https://nodejs.org/en/ 中文网:http://nodejs.cn/ 我们会发现这样一句话: 翻译成中文如下: Node.js 是一个基于 ...
- bzoj1630 / bzoj2023 [Usaco2005 Nov]Ant Counting 数蚂蚁
Description 有一天,贝茜无聊地坐在蚂蚁洞前看蚂蚁们进进出出地搬运食物.很快贝茜发现有些蚂蚁长得几乎一模一样,于是她认为那些蚂蚁是兄弟,也就是说它们是同一个家族里的成员.她也发现整个 ...
- Linux内核分析 03
一,构造一个简单的Linux系统MenuOS 1.Linux内核源代码简介 回顾一下前面的三大法宝和两把宝剑. arch/x86目录下的代码需要重点关注 阅读代码的时候把除了x86以外的都删掉会有利于 ...
- 20145326《Java程序设计》第二周学习总结
20145326<Java程序设计>第二周学习总结 教材学习内容总结 本周学习教材第三章,本章主要讲述了java语言中的一些基础语法,java是个支持面向对象的程序语言,但在正式进入面向对 ...
- linux中readl()和writel()函数---用于读写寄存器
writel() 往内存映射的 I/O 空间上写数据,wirtel() I/O 上写入 32 位数据 (4字节). 原型: #include <asm/io.h> void writel ...
- RC 522模块在LINUX平台调试笔记
硬件平台: 1 主控:SMDK Exynos4412 POP S5M8767A 2 RFID模块:君盾集团提供的RC522模块 3 通信接口:SPI 软件平台:Android ICS & ke ...
- hashmap实现及哈希冲突
原文: https://www.cnblogs.com/peizhe123/p/5790252.html HashMap 采用一种所谓的“Hash 算法”来决定每个元素的存储位置.当程序执行 map. ...
- hdu 5687 Problem C trie树
Problem C Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Prob ...