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. Set,List,Map的区别

    最近在学习struct2中OGNL表达式的过程中,发现自己对set,list,map存在只是欠缺,在百度的过程中发现了此文觉得讲的不错,放到自己博客以便再次查阅,也希望更多地菜鸟看到. java集合的 ...

  2. Flume1.7.0概述

    Flume概述 常见的开源数据收集系统有: 非结构数据(日志)收集 Flume 结构化数据收集(传统数据库与 Hadoop 同步) Sqoop:全量导入 Canal(alibaba):增量导入 Dat ...

  3. centos7 firewall开放查看关闭端口

    查看所有打开的端口: firewall-cmd --zone=public --list-ports 添加 firewall-cmd --zone=public --add-port=80/tcp - ...

  4. JSONP跨站访问

    js中几种实用的跨域方法原理详解 这里说的js跨域是指通过js在不同的域之间进行数据传输或通信,比如用ajax向一个不同的域请求数据,或者通过js获取页面中不同域的框架中(iframe)的数据.只要协 ...

  5. Python3.x:判断字符串是否为全数字、英文、大写、小写、空白字符

    Python3.x:判断字符串是否为全数字.英文.大写.小写.空白字符 判断接字符串是否为数字: str = raw_input("please input the number:" ...

  6. mac 安装python3

    Python有两个版本,一个是2.x版,一个是3.x版,这两个版本是不兼容的. 现在 Mac 上默认安装的 python 版本为  2.7 版本,若 安装 新版本需要 通过 该地址进行下载: http ...

  7. Pandas可视化

    基本绘图:绘图 Series和DataFrame上的这个功能只是使用matplotlib库的plot()方法的简单包装实现.参考以下示例代码 - import pandas as pd import ...

  8. php中POST与GET区别

    如果有人问你,GET和POST,有什么区别?你会如何回答? 我的经历 前几天有人问我这个问题.我说GET是用于获取数据的,POST,一般用于将数据发给服务器之用. 这个答案好像并不是他想要的.于是他继 ...

  9. HTML5笔记学习(canvas)

    来源于<HTML5高级程序设计> css3圆角 border-radius旋转变换 transform:rotate(); 变换 transformation动画 animation过度 ...

  10. shell 数组操作

    1. 定义数组: var_array=(one two three four five) 2.常用操作 获取数组长度: ${#var_array[@]} 获取所有数组元素:  ${var_array[ ...