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
题意:找出一个字符串的循环列中最小和最大的那个字符串,并求出格数
题解:个数就是最小循环数,用kmp的next数组即可,然后用字符串的最小表示法求,最大的同理wa点:刚开始想直接暴力结果mle,莫名其妙,我以为应该是tle,结果改用kmp了之后,直接暴力求最小还是tle, 最后实在没办法看的最小表示法,还有一点就是自己脑残,写成了ans=(slen%ans ? ans:slen/ans)不能整除明明是1啊!!
不过还是没搞懂为啥不能直接循环求最小,时间复杂度明明是一样的,最小表示法时间复杂度也是O(n)啊
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<iomanip>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define ll long long
#define mod 10007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1 using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=(<<)-,inf=0x3f3f3f3f; int Next[N],slen;
string str; void getnext()
{
int k=-;
Next[]=-;
for(int i=;i<slen;i++)
{
while(k>-&&str[k+]!=str[i])k=Next[k];
if(str[k+]==str[i])k++;
Next[i]=k;
}
}
int solve(bool flag)
{
int i=,j=,k=;
while(i<slen&&j<slen&&k<slen){
int t=str[(i+k)%slen]-str[(j+k)%slen];
if(!t)k++;
else
{
if(flag)t> ? i=i+k+:j=j+k+;
else t< ? i=i+k+:j=j+k+;
if(i==j)j++;
k=;
}
}
return min(i,j);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
// cout<<setiosflags(ios::fixed)<<setprecision(2);
while(cin>>str){
slen=str.size();
getnext();
int ans=slen-Next[slen-]-;
ans=(slen%ans ? :slen/ans);
cout<<solve()+<<" "<<ans<<" "<<solve()+<<" "<<ans<<endl;
}
return ;
}

hdu3374 kmp+最小表示法的更多相关文章

  1. hdu-3374(kmp+最小表示法)

    题意:给你一个字符串,这个字符串我们可以把把他变成n个字符串按照以下规则:将当前字符串第一个放到字符串最后一位,字符串的下标依次向前推一位,比如:s[1] s[2 ]s[3] s[4]->s[2 ...

  2. hdu5442(2015长春赛区网络赛1006)后缀数组+KMP /最小表示法?

    题意:给定一个由小写字母组成的长度为 n 的字符串,首尾相连,可以从任意一个字符开始,顺时针或逆时针取这个串(长度为 n),求一个字典序最大的字符串的开始字符位置和顺时针或逆时针.如果有多个字典序最大 ...

  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. hdu3374 最大最小表示法 +kmp

    #include <iostream> #include <algorithm> #include <string.h> #include <cstdio&g ...

  5. hdu3374最小表示法+KMP

    题意:       给你一个最长100W的串,然后让你找到最小同构子串,还有最大同构子串的下标,最小同构子串就是把字符串连接成一个环,然后选择一个地方断开,得到的一个ASCII最小的子串(求最大同理) ...

  6. hdu3374 String Problem KMP+最大最小表示法

    Give you a string with length N, you can generate N strings by left shifts. For example let consider ...

  7. HDU-3374-String Problem(最小表示法, KMP)

    链接: https://vjudge.net/problem/HDU-3374 题意: Give you a string with length N, you can generate N stri ...

  8. 【KMP】【最小表示法】NCPC 2014 H clock pictures

    题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1794 题目大意: 两个无刻度的钟面,每个上面有N根针(N<=200000),每个 ...

  9. Manacher模板,kmp,扩展kmp,最小表示法模板

    *N]; //储存临时串 *N];//中间记录 int Manacher(char tmp[]) { int len=strlen(tmp); ; ;i<len;i++) { s[cnt++]= ...

随机推荐

  1. postman接口测试——笔记

    接口测试理论:   一.接口 1.程序内部接口:方法与方法之间,模块与模块之间的交互,程序内部抛出的接口,比如bbs系统,有登录模块,发帖模块等等,那你要发帖就必须先登录,那么这两个模块就得有交互,它 ...

  2. 教你如何在linux下查看服务是否已经启动或者关闭

    1. # ps aux | grep 服务名称(ps 的参数是可以颠倒使用没问题) 2. # netstat -tunple | grep 服务端口 3.bind() 80 in using 代表的含 ...

  3. python之路----模块与序列化模块

    认识模块 什么是模块 什么是模块? 常见的场景:一个模块就是一个包含了python定义和声明的文件,文件名就是模块名字加上.py的后缀. 但其实import加载的模块分为四个通用类别: 1 使用pyt ...

  4. (mac)阿里云ECS服务器配置过程

    -----首先本人是半只脚入门的iOS开发者,弄这个只是单纯想多学点东西. -----阿里云服务器的配置选择:既然是学习用的,最最基础的配置就行了.1M带宽,1核1G...这就不详述了.没啥可选的,( ...

  5. 干货:Java多线程详解(内附源码)

      线程是程序执行的最小单元,多线程是指程序同一时间可以有多个执行单元运行(这个与你的CPU核心有关). 在java中开启一个新线程非常简单,创建一个Thread对象,然后调用它的start方法,一个 ...

  6. jsp/servlet/mysql/linux基本概念和操作

    一.什么是OOP编程? 面向对象,以结果为导向,并封装整个过程,并尽可能地增加代码的复用性和可扩展性...... 二.Junit? JUnit是一个java语言的单元测试框架.Junit测试时程序员测 ...

  7. 记一次ping: unknown host错误

    虚拟机上一台主机,之前一直在用,可以通过xshell连接,但是忽然发现ping百度失败了! [root@mgt02 ~]# ping www.baidu.com ping: unknown host ...

  8. map按value值查找——find_if的使用(转载)

    转载:http://www.cnblogs.com/xufeiyang/archive/2012/05/09/2491871.html CValueFind #ifndef _CVALUEFIND_H ...

  9. JS控制页面内容

    JS操作页面内容 innerText:普通标签内容(自身文本与所有子标签文本)innerHTML:包含标签在内的内容(自身文本及子标签的所有)value:表单标签的内容outerHTML:包含自身标签 ...

  10. Linux驱动模块的Makefile分析【转】

    本文转载自:http://blog.chinaunix.net/uid-29307109-id-3993784.html 1. 获取内核版本 当设备驱动需要同时支持不同版本内核时,在编译阶段,内核模块 ...