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 只知道最小最大表示法。但是名次没思路。 后来看题解是循环节。。。。
脑子真是废了。。 循环节用next数组搞定 即可
 #include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn=;
char s[maxn],t[maxn];
int Next[maxn],len; void prekmp(char* s) {
int i,j;
j=Next[]=-;
i=;
while(i<len) {
while(j!=-&&s[i]!=s[j]) j=Next[j];
if(s[++i]==s[++j]) Next[i]=Next[j];
else Next[i]=j;
}
} int getmin(char* str) {
int len2=strlen(str);
int i=,j=,k=;
while(i<len&&j<len&&k<len) {
int tmp=s[(i+k)%len2]-s[(j+k)%len2];
if(!tmp) k++;
else {
if(tmp<) j+=k+;
else i+=k+;
if(i==j) j++;
k=;
}
}
return min(i,j);
} int getmax(char* str) {
int len2=strlen(str);
int i=,j=,k=;
while(i<len&&j<len&&k<len) {
int tmp=s[(i+k)%len2]-s[(j+k)%len2];
if(!tmp) k++;
else {
if(tmp<) i+=k+;
else j+=k+;
if(i==j) j++;
k=;
}
}
return min(i,j);
} int main() {
while(~scanf("%s",s)) {
len=strlen(s);
prekmp(s);
int num=,len1=len-Next[len];
if(len%len1==)
num=len/len1;
strcpy(t,s);
strcat(s,t);
printf("%d %d %d %d\n",getmin(s)+,num,getmax(s)+,num);
}
}

kuangbin专题十六 KMP&&扩展KMP HDU3347 String Problem(最小最大表示法+kmp)的更多相关文章

  1. kuangbin专题十六 KMP&&扩展KMP HDU2609 How many (最小字符串表示法)

    Give you n ( n < 10000) necklaces ,the length of necklace will not large than 100,tell me How man ...

  2. kuangbin专题十六 KMP&&扩展KMP HDU2328 Corporate Identity

    Beside other services, ACM helps companies to clearly state their “corporate identity”, which includ ...

  3. kuangbin专题十六 KMP&&扩展KMP HDU1238 Substrings

    You are given a number of case-sensitive strings of alphabetic characters, find the largest string X ...

  4. kuangbin专题十六 KMP&&扩展KMP HDU3336 Count the string

    It is well known that AekdyCoin is good at string problems as well as number theory problems. When g ...

  5. kuangbin专题十六 KMP&&扩展KMP POJ3080 Blue Jeans

    The Genographic Project is a research partnership between IBM and The National Geographic Society th ...

  6. kuangbin专题十六 KMP&&扩展KMP HDU3746 Cyclic Nacklace

    CC always becomes very depressed at the end of this month, he has checked his credit card yesterday, ...

  7. kuangbin专题十六 KMP&&扩展KMP HDU2087 剪花布条

    一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图案.对于给定的花布条和小饰条,计算一下能从花布条中尽可能剪出几块小饰条来呢? Input输入中含有一些数据,分别是成对出现的花布条和小 ...

  8. kuangbin专题十六 KMP&&扩展KMP HDU1686 Oulipo

    The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e ...

  9. kuangbin专题十六 KMP&&扩展KMP HDU1711 Number Sequence

    Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], ...... , b[M] (1 <= M ...

随机推荐

  1. HTML元素(包括HTML5)的标签、属性及事件大全

    1.标签列表 标签 描述 <!–…–> 定义注释. <!DOCTYPE> 定义文档类型. <a> 定义超链接. <abbr> 定义缩写. <acr ...

  2. apache2不识别php

    sudo apt-get install libapache2-mod-php7.0 sudo a2enmod php7.0 sudo service apache2 restart 注意:Apach ...

  3. eclipse 中文版 变成 英文版 方法

    找到目录运行命令 “eclipse.exe -nl en”

  4. 根据/proc/meminfo对空闲内存进行占用

    #include <stdio.h> #include <sys/sysinfo.h> #include <linux/kernel.h> /* 包含sysinfo ...

  5. [cf557d]Vitaly and Cycle(黑白染色求奇环)

    题目大意:给出一个 n 点 m 边的图,问最少加多少边使其能够存在奇环,加最少边的情况数有多少种. 解题关键:黑白染色求奇环,利用数量分析求解. 奇环:含有奇数个点的环. 二分图不存在奇环.反之亦成立 ...

  6. ROS Learning-011 beginner_Tutorials (编程) 编写 ROS 话题版的 Hello World 程序(Python版)

    ROS Indigo beginner_Tutorials-10 编写 ROS 话题版的 Hello World 程序(Python版) 我使用的虚拟机软件:VMware Workstation 11 ...

  7. bzoj1787 紧急集合

    传送门 题目 Input Output 分析 看到这个题不难想到倍增LCA,然后我们考虑如何计算.我们分别求出3个点中任意两点的LCA,为了走的步数最少所以肯定是先有两个点相遇然后另一个点走的它们相遇 ...

  8. Entity Framework Tutorial Basics(12):Model First

    Model First development with Entity Framework: In the Model First approach, you create Entities, rel ...

  9. ubuntu基础知识与技巧

    root用户与超级用户的切换 (1)  sudo -i (2)  sudo su (3)  su root 安装升级 查看软件xxx安装内容 dpkg -L xxx 查找软件库中的软件 apt-cac ...

  10. leetcode mergeKsortedlink

    代码:这个代码是有问题的,问题的产生是map中不能存放相同的值. #include<iostream> #include<vector> #include<cmath&g ...