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. 使用jmx4perl和j4psh接管Jolokia

    在ActiveMQ的API中,内置了Jolokia . 可以使用jmx4perl来安装: $ perl -MCPAN -e shell Terminal does not support AddHis ...

  2. QTP11使用DOM XPath以及CSS识别元素对象

    我们知道,像DOM,Html,CSS,XPath等对对象的识别策略广泛运用于一些开源的工具,例如:Selenium,Watir,Watir-Webdriver,以前qtp版本是不支持这些东西的,现在q ...

  3. 包学会之浅入浅出Vue.js:开学篇

    2016年,乃至接下来整个2017年,如果你要问前端技术框架什么最火,那无疑就是前端三巨头:React.Angular.Vue.没错,什么jQuery,seaJs,gulp等都逐渐脱离了热点.面试的时 ...

  4. elasticsearch(4) 安装 (两台)

    环境: centos7  jdk8   elasticsearch1.7.1 安装JDK 确认现有JDK版本 # java –version 安装以及配置环境变量 # tar zxvf jdk-8u6 ...

  5. HBase入门基础教程 HBase之单机模式与伪分布式模式安装

    在本篇文章中,我们将介绍Hbase的单机模式安装与伪分布式的安装方式,以及通过浏览器查看Hbase的用户界面.搭建HBase伪分布式环境的前提是我们已经搭建好了Hadoop完全分布式环境,搭建Hado ...

  6. 关于uboot的一些优化

    转载于:http://blog.163.com/solylee@126/blog/static/1718231572010101910485331/ 本人的开发环境是u-boot-1.1.6版本,fe ...

  7. oracle --(三)数据段(segment)

    基本关系:数据库---表空间---数据段---分区---数据块 数据段(segment)段(segment)由一系列的extent组成.通常一张表是一个segment. Oracle中的段可以分成4种 ...

  8. 使用ffmpeg合并视频

    命令: ffmpeg -i concat:"1.avi|2.avi" -vcodec copy -acodec copy "3.avi" ffmpeg下载:ht ...

  9. 安装了多个php版本,如何编译扩展

    cd /data/php-5.5.35/ext/mysqli  找到安装包目录下面的ext目录 ./configure --with-php-config=/usr/local/php5/bin/ph ...

  10. STM32数据类型定义

    #ifndef __STM32F10x_TYPE_H #define __STM32F10x_TYPE_H typedef signed long s32; typedef signed short ...