HDU(3374) (KMP + 最小表示法)
来源:互联网 发布:php utf8转gbk 编辑:程序博客网 时间:2024/06/05 19:44
题目:http://acm.hdu.edu.cn/showproblem.php?pid=3374最小表示法:http://tobyaa.blog.163.com/blog/static/30248591201261604349913/#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>using namespace std;const int maxn = 1000005;char str[maxn];int next[maxn];void get_next(char str[],int next[]){ int i = 0,j = -1; next[0] = -1; int len = (int)strlen(str); while(i < len){ if(j == -1 || str[i] == str[j]) next[++i] = ++j; else j = next[j]; }}int getmin(char str[]){ int len = (int)strlen(str); int i = 0,j = 1,k = 0; while(i < len && j < len && k < len){ int t = str[(i + k)%len] - str[(j + k)%len]; if(!t) k++; else{ if(t < 0) j += k+1; else i += k+1; if(i == j) j++; k = 0; } } return i>j?j:i;}int getmax(char str[]){ int len = (int)strlen(str); int i = 0,j = 1,k = 0; while(i < len && j < len && k < len){ int t = str[(i + k)%len] - str[(j + k)%len]; if(!t) k++; else{ if(t > 0) j += k+1; else i += k+1; if(i == j) j++; k = 0; } } return i>j?j:i;}int main(){ while(~scanf("%s",str)){ get_next(str, next); int len = (int)strlen(str); int time = 1; if(len%(len - next[len]) == 0) time = len/(len - next[len]); printf("%d %d %d %d\n",getmin(str)+1,time,getmax(str)+1,time); } return 0;}
0 0
- HDU(3374) (KMP + 最小表示法)
- hdu 3374 最小表示法加 KMP
- HDU 3374 (KMP 最小表示法)
- HDU 3374String Problem(最大最小表示法+KMP)
- hdu 3374 String Problem (最小表示法+KMP)
- hdu 3374 String Problem (最小表示法+kmp next[])
- hdu 3374 String Problem 【kmp+最小(大)表示法】
- hdu 3374 String Problem(最小表示法+kmp)
- HDU 3374 String Problem(最小表示法·KMP)
- hdu 3374 String Problem (kmp+最大最小表示法)
- HDU 3374 String Problem (KMP+最大最小表示法)
- HDU 3374 String Problem(最大最小表示法+kmp)
- hdu 3374 String Problem(KMP+最大最小表示法)
- HDU 3374 KMP 最大表示法 最小表示法
- HDU 3374 String Problem(最小最大表示法+KMP)
- HDU 3374 String Problem KMP-最小最大表示法
- hdu 3374 String Problem(字符串最小最大表示法+kmp)
- 【KMP】 HDU 3374 String Problem 最小表示法
- linux环境下的rmi常见问题
- POJ(2761)Feed the dogs (树状数组+离散化+贪心)
- FZU Problem 1926 填空(KMP好题一枚,确实好)
- Codeforces Round #183 (Div. 2) B. Calendar
- FZU Problem 2030 括号问题
- HDU(3374) (KMP + 最小表示法)
- HOJ (1042) 整数划分
- HDU(2509) Be the Winner /HDU(1907) John (Nim 博弈)
- HDU(1525)Euclid's Game
- HDU(1847)Good Luck in CET-4 Everybody!
- HDU(2149)Public Sale 博弈
- HDU(2897)邂逅明下
- HDU(1851) A Simple Game (博弈)
- HDU(1850) Being a Good Boy in Spring Festival (博弈)