hdu3374 String Problem
来源:互联网 发布:淘宝首页装修视频教程 编辑:程序博客网 时间:2024/04/30 00:41
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3374
题解:循环移位,找字典序最前的和字典序最后的下标标号,然后把次数也输出来。
用最小表示法和最大表示法找到字典序最小和最大的字符串。用kmp计算出现的次数(最小循环周期)。
//http://blog.csdn.net/coraline_m/article/details/9834619
#include <stdio.h>#include <string.h>#define MAXN 1000002char str1[MAXN];int next[MAXN],len;void getNext(){int i=0,j=-1;next[0]=-1;while(str1[i]!='\0'){if(j==-1||str1[i]==str1[j]){i++;j++;next[i]=j;}elsej=next[j];}}int getMin()//最小表示法{int i=0,k=0,j=1,t;while(i<len&&j<len&&k<len){t=str1[(i+k)%len]-str1[(j+k)%len];if(!t)k++;else{if(t>0)i+=(k+1);elsej+=(k+1);if(i==j)j++;k=0;}}return i<j?i:j;}int getMax()//最大表示法{int i=0,k=0,j=1,t;while(i<len&&j<len&&k<len){t=str1[(i+k)%len]-str1[(j+k)%len];if(!t)k++;else{if(t>0)j+=(k+1);elsei+=(k+1);if(i==j)j++;k=0;}}return i<j?i:j;}int main(){int cnt,temp;while(scanf("%s",str1)!=EOF){len=strlen(str1);getNext();temp=len-next[len];cnt=1;if(len%temp==0)cnt=len/temp;printf("%d %d %d %d\n",getMin()+1,cnt,getMax()+1,cnt);}return 0;}
- hdu3374 String Problem
- 【KMP】 hdu3374 String Problem
- hdu3374 String Problem
- hdu3374---String Problem
- hdu3374 String Problem(KMP+最小表示法)
- HDU3374 String Problem(KMP + 最小表示法)
- hdu3374 String Problem (字符串最小表示)
- HDU3374(String Problem)字符串-最小表示法+KMP
- hdu3374 String Problem(最小最大表示法+KMP)
- HDU3374 String Problem(KMP + 最大最小表示)
- hdu3374-最小表示法&&kmp求循环节-String Problem
- HDU3374 String Problem(kmp,最大最小表示法)
- hdu3374
- HDU3374
- String Problem
- hdu 3374 String Problem
- HDU 3374 String Problem
- W String Problem
- hdu 1501 Zipper (DFS)
- 安卓线程问题
- 开源项目之Android http请求及缓存框架(GalHttprequest)
- boost utility
- 产品经理必看书籍推荐
- hdu3374 String Problem
- 苹果更新App Store审核指南
- hdu 4474 Yet Another Multiple Problem (余数判重 + BFS)
- 杭电 1870 愚人节的礼物
- iOS 数据持久化
- iOS面试题(三)
- java基础 线程理解
- boost typeof
- SQL 已更新或删除的行值要么不能使该行成为唯一行(sqlserver中有多行所有的列重复的数据,无法更新或删除问题)