Give you a string with length N, you can generate N strings by left shifts. For example let consider the string “SKYLONG”, we can generate seven strings: 
String Rank 
SKYLONG 1 
KYLONGS 2 
YLONGSK 3 
LONGSKY 4 
ONGSKYL 5 
NGSKYLO 6 
GSKYLON 7 
and lexicographically first of them is GSKYLON, lexicographically last is YLONGSK, both of them appear only once. 
  Your task is easy, calculate the lexicographically fisrt string’s Rank (if there are multiple answers, choose the smallest one), its times, lexicographically last string’s Rank (if there are multiple answers, choose the smallest one), and its times also. 

Input  Each line contains one line the string S with length N (N <= 1000000) formed by lower case letters.OutputOutput four integers separated by one space, lexicographically fisrt string’s Rank (if there are multiple answers, choose the smallest one), the string’s times in the N generated strings, lexicographically last string’s Rank (if there are multiple answers, choose the smallest one), and its times also.Sample Input

abcder
aaaaaa
ababab

Sample Output

1 1 6 1
1 6 1 6
1 3 2 3
#include<bits/stdc++.h>
using namespace std;
const int maxn=;
char a[maxn]; int Next[maxn],num,L;
void KMP()
{
for(int i=,j=;i<=L;i++){
while(j&&a[i]!=a[j+]) j=Next[j];
if(a[i]==a[j+]) j++;
Next[i]=j;
}
num=L%(L-Next[L])?:L/(L-Next[L]);
}
int minexpress()
{
int i=,j=,k=;
while(i<=L&&j<=L&&k<L){
int ti=(i+k>L?i+k-L:i+k);
int tj=j+k>L?j+k-L:j+k;
if(a[ti]==a[tj]) k++;
else {
if(a[ti]<a[tj]) j+=k+;
else i+=k+;
if(i==j) j++;
k=;
}
}
return min(i,j);
}
int maxexpress()
{
int i=,j=,k=;
while(i<=L&&j<=L&&k<L){
int ti=i+k>L?i+k-L:i+k;
int tj=j+k>L?j+k-L:j+k;
if(a[ti]==a[tj]) k++;
else {
if(a[ti]>a[tj]) j+=k+;
else i+=k+;
if(i==j) j++;
k=;
}
}
return min(i,j);
}
int main()
{
int T,Min,Max;
while(~scanf("%s",a+)){
L=strlen(a+);
KMP();
Min=minexpress();
Max=maxexpress();
printf("%d %d %d %d\n",Min,num,Max,num);
}
return ;
}

HDU - 3374:String Problem (最小表示法模板题)的更多相关文章

  1. hdu String Problem(最小表示法入门题)

    hdu 3374 String Problem 最小表示法 view code#include <iostream> #include <cstdio> #include &l ...

  2. HDU 3374 String Problem (KMP+最大最小表示)

    HDU 3374 String Problem (KMP+最大最小表示) String Problem Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  3. hdu 3374 String Problem(kmp+最小表示法)

    Problem Description Give you a string with length N, you can generate N strings by left shifts. For ...

  4. HDU - 3374 String Problem (kmp求循环节+最大最小表示法)

    做一个高产的菜鸡 传送门:HDU - 3374 题意:多组输入,给你一个字符串,求它最小和最大表示法出现的位置和次数. 题解:刚刚学会最大最小表示法,amazing.. 次数就是最小循环节循环的次数. ...

  5. String Problem HDU - 3374(最大最小表示法+循环节)

    题意: 给出一个字符串,问这个字符串经过移动后的字典序最小的字符串的首字符位置和字典序最大的字符串的首字符的位置,和能出现多少次最小字典序的字符串和最大字典序的字符串 解析: 能出现多少次就是求整个字 ...

  6. HDU 3374 String Problem(KMP+最大/最小表示)

    String Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  7. HDU 3374 String Problem

    最大最小表示法与KMP求循环节 最大最小表示法 最大最小表示法与KMP求循环节的模板题, #include <iostream> #include <cstdio> #incl ...

  8. hdu 3374 String Problem (kmp+最大最小表示法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3374 题目大意:输出最大和最小的是从哪一位开始的,同时输出最小循环节的个数. 这里简单介绍对字符串最小 ...

  9. hdu 3374 String Problem(最小表示法+最大表示法+kmp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3374 题意:给出一个字符串问这个字符串最小表示的最小位置在哪,还有有几个最小表示的串.最大表示的位置在 ...

随机推荐

  1. CWinApp类CMultiDocTemplate类CDocument类CView类的关系

    转自:http://blog.csdn.net/bboot/article/details/26884011 不得不转,瞬间搞清了很多问题,短小精悍 1.CWinApp类   它包含并管理着应用程序的 ...

  2. nginx2

    Nginx的高可用是keeplived,keeplived是为lvs服务的. Nginx上分别安装keepalived,keepalived之间通过心跳交流,主节点宕机备节点起来.keepalived ...

  3. linux mkisofs(genisoimage)命令用法

    功能说明:建立ISO 9660映像文件. 常用命令:genisoimage -o imagename.iso file 语 法:mkisofs [-adDfhJlLNrRTvz][-print-siz ...

  4. Spring 之 @ComponentScan以及mock Spring MVC

    [ @ComponentScan] 纠正:可以成功 Autowired 的原因是我在另外一个 config 文件中扫描了根包,这会顺带扫描所有该包的子包 还有,,上面的写法容易出错,建议这样写, @C ...

  5. 【Head First Servlets and JSP】笔记20:EL以及<jsp:useBean ....>的补充

    1.EL的英文是Expression Language,译成中文就是“表达式语言”.这是一种给前端程序员使用的脚本语言,EL与Java表达式相比并没有什么“天壤之别”,在后端程序员看来多少有点“多此一 ...

  6. Python3:文件读写

    Python3:文件读写 open f = open('filename','r') # 读模式 f = open('filename','w') # 写模式 f = open('filename', ...

  7. Oracle数据库PLSQL的中文乱码显示全是问号

    plsql连接数据库乱码问题 缘由: 小师妹周末叫我帮她重装数据库,这么大好的周末时光不出去玩儿,给她装数据库这不是很蛋疼么. 我问她为什么要重装,她说:数据存入数据库后,中文字符有乱码,一定是我上次 ...

  8. 混合开发的大趋势之一React Native之Image (脑动理解)

    文章是宝宝自己写的,你可以转走,标明哪来的就行王亟亟的大牛之路 国庆这些天要么旅游要么WOW,感觉整个人都废了.. 直接从黄种人晒成了非洲大酋长..然而还是无橙,这礼拜要做7天,昨天把单元测试的东西整 ...

  9. JAVA基础补漏--反射

    获得CLASS的三种方式: 1.Class.forname("全类名"):将字节码文件加载进内存,返回Class对象. 多用于配置文件,将类名放到配置文件中,读取配置文件,加载类 ...

  10. springmvc学习(2)

    SpringMvc是最主流的MVC框架之一. Spring3.0后全面超越Struts2,成为最优先的MVC框架 SpringMVC通过一套MVC注解,让POJO成为处理请求的控制器,而无须实现任何借 ...