POJ 2406

其实就是一个简单的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)的更多相关文章

  1. poj 2406Power Strings

    http://poj.org/problem?id=2406 #include<cstdio> #include<cstring> #include<algorithm& ...

  2. POJ 1961 Period( KMP )*

    Period Time Limit: 3000MSMemory Limit: 30000K Total Submissions: 12089Accepted: 5656 Description For ...

  3. POJ 2406 Power Strings (KMP)

    Power Strings Time Limit: 3000MSMemory Limit: 65536K Total Submissions: 29663Accepted: 12387 Descrip ...

  4. poj 2406 Power Strings kmp算法

    点击打开链接 Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 27368   Accepted:  ...

  5. poj 2406 Power Strings (kmp 中 next 数组的应用||后缀数组)

    http://poj.org/problem?id=2406 Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submiss ...

  6. POJ 2406 - Power Strings - [KMP求最小循环节]

    题目链接:http://poj.org/problem?id=2406 Time Limit: 3000MS Memory Limit: 65536K Description Given two st ...

  7. POJ:2406-Power Strings(寻找字符串循环节)

    Power Strings Time Limit: 3000MS Memory Limit: 65536K Description Given two strings a and b we defin ...

  8. POJ 2406 Power Strings KMP运用题解

    本题是计算一个字符串能完整分成多少一模一样的子字符串. 原来是使用KMP的next数组计算出来的,一直都认为是能够利用next数组的.可是自己想了非常久没能这么简洁地总结出来,也仅仅能查查他人代码才恍 ...

  9. poj 2406 Power Strings(KMP变形)

    Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 28102   Accepted: 11755 D ...

随机推荐

  1. 2018 Multi-University Training Contest 2 Solution

    A - Absolute 留坑. B - Counting Permutations 留坑. C - Cover 留坑. D - Game puts("Yes") #include ...

  2. PDO的三种连接数据库的方式

    PDO的三种连接数据库的方式   PDO的出现是为了解决PHP与各个数据库的连接处理都有各自的函数的问题,它的高度抽象,使得使用起来极其的方便.由于最常用的搭配就是PHP+Mysql,所以这里就以连接 ...

  3. 20145105 《Java程序设计》第4周学习总结

    20145105 <Java程序设计>第4周学习总结 教材学习内容总结 第六章 继承与多态 一.何谓继承 (一)继承共同行为 继承基本上就是避免多个类间重复定义共同行为. 如:下述代码将剑 ...

  4. IntelliJ IDEA 常用快捷键,maven依赖图,个性化设置,禁用Search Everywhere

    查看idea 中jar关系图 快捷键: Ctrl+/ 用于注释,取消注释 Ctrl+Shift+F 全文搜索 Ctrl+F 单页面查找 Ctrl+Alt+Shift+L  格式化代码 ======== ...

  5. 2016"百度之星" - 初赛(Astar Round2A) A.All X 矩阵快速幂

    All X  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 65536/65536 K (Java/Others) Problem Des ...

  6. 上海仪电Azure Stack技术深入浅出系列1:谈Azure Stack在私有云/混合云生态中的定位

    2.2 Azure Stack Azure Stack到2017年7月才提供GA版本,但目前还是可以通过技术预览版了解该技术.Azure Stack本质上是核心Azure服务的一个私有实例. Micr ...

  7. 从invalidAuthenticationToken❌想到需要忽略:verify_authenticity_token。

    https://www.cnblogs.com/chentianwei/diary/2018/07/11/9296126.html 这篇日记记录了我遇到的invalidAuthenticaitonTo ...

  8. 006——php字符串中的处理函数(五)

    <?php /** * 一.addslashes() 在预定义字符串前添加反斜杠 * * stripslashes() 把转义字符串前的反斜杠删除 * get_magic_quotes_gpc( ...

  9. 如何在.Net的MySqlCommand里面使用MySql用户自定义变量?

    Mysql使用@符号代表变量,但C#也恰好使用@代表用户自定义变量,这样两者就会正好冲突了. SELECT () AS rowId, u.*, r.RoleName FROM userinfo u L ...

  10. HDU 4686 Arc of Dream 矩阵快速幂,线性同余 难度:1

    http://acm.hdu.edu.cn/showproblem.php?pid=4686 当看到n为小于64位整数的数字时,就应该有个感觉,acm范畴内这应该是道矩阵快速幂 Ai,Bi的递推式题目 ...