#include <iostream>
#include <algorithm>
#include <string.h>
#include <cstdio>
#include <vector>
using namespace std;
const int maxn=;
int MinRepresstation(char * S, int len ) {
int i = , j = , k = ;
while(i < len && j < len)
{
k = ;
while(k < len && S[(i + k)%len] == S[(j + k)%len])
k++;
if(k >= len)
break;
if(S[(i + k)%len] > S[(j + k)%len])
i = max(i + k + , j + );
else
j = max(i + , j + k + );
}
return min(i ,j);
}
int MaxRepresstation(char * S, int len ) {
int i = , j = , k = ;
while(i < len && j < len)
{
k = ;
while(k < len && S[(i + k)%len] == S[(j + k)%len])
k++;
if(k >= len)
break;
if(S[(i + k)%len] > S[(j + k)%len])
j = max(i + , j + k + );
else
i = max(i + k + , j + );
}
return min(i ,j);
}
char s[maxn];
char s1[maxn],s2[maxn];
void getFail(char *P, int *f, int m)
{
f[]=; f[]=;
for(int i=; i<m; i++)
{
int j=f[i];
while(j&&P[i]!=P[j])j=f[j];
f[i+]=P[i]==P[j]?j+:;
}
}
int find(char *T,char *P, int *f,int n, int m)
{
getFail(P,f,m);
int j=;
int num=;
for(int i=; i<n-; i++)
{
while(j&&P[j]!=T[i])j=f[j];
if(P[j]==T[i])j++;
if(j==m){
num++; j=f[j];
}
}
return num;
}
int F[maxn]; int main()
{ while(gets(s))
{ int len=strlen(s);
int d1=MinRepresstation(s,len);
int d2=MaxRepresstation(s,len);
for(int i = ; i < len ; i ++)
s[ i + len ] = s[ i ];
for(int i=; i<len; i++)
{
s1[i]=s[(i+d1)%len];
s2[i]=s[(i+d2)%len];
}
int ans1=find(s,s1,F,len*,len);
int ans2=find(s,s2,F,len*,len);
printf("%d %d %d %d\n",d1+,ans1,d2+,ans2);
} return ;
}

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

  1. Hdu 5442 Favorite Donut (2015 ACM/ICPC Asia Regional Changchun Online 最大最小表示法 + KMP)

    题目链接: Hdu 5442 Favorite Donut 题目描述: 给出一个文本串,找出顺时针或者逆时针循环旋转后,字典序最大的那个字符串,字典序最大的字符串如果有多个,就输出下标最小的那个,如果 ...

  2. hdu3374最小表示法+KMP

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

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

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

  4. 【HDU3374】 String Problem (最小最大表示法+KMP)

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

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

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

  6. hdu3374 kmp+最小表示法

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

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

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

  8. HDU 3374 最小/大表示法+KMP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3374 题意:给定一个串s,该串有strlen(s)个循环同构串,要求输出字典序最小的同构串的下标,字典 ...

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

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

随机推荐

  1. 联系customer的js

    import api from '@/js/api'; export var conService = function getInfoSend() { var loginState = localS ...

  2. 在Windows Server 2008 R2 Server中,上传视频遇到的问题(一)

    在Windows 2008 R2 Server中,上传视频不能播放,以及服务器大小限制问题,这里记录我的解决方法,以免再次遇到,无所适从. 1.上传视频不能播放 打开IIS,找到“MIME类型”,如下 ...

  3. Linux ifconfig 命令

    在centos6 自带ifconfig 在centos7 默认不带ifconfig,需要自己安装 ifconfig命令用来配置或查看网卡接口,常见用法如下: 安装ifconfig命令 [root@my ...

  4. mysql报错Multi-statement transaction required more than 'max_binlog_cache_size' bytes of storage

    mysql报错Multi-statement transaction required more than 'max_binlog_cache_size' bytes of storage 在执行cr ...

  5. 数据库——MongoDB

    what's the MongoDB MongoDB是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的.他支持的数据结构非常松散,是类似json的bson格式 ...

  6. python实现根据当前时间创建目录并输出日志

    举个例子:比如我们要实现根据当前时间的年月日来新建目录来存放每天的日志,当前时间作为日志文件名称:代码如下: #!/usr/bin/env python3 # _*_ coding: utf-8 _* ...

  7. OCP-第二节课.md

    第一. MQ(压队列)    PGA    share pool 三层结构 应用服务器--->中间件--->数据库 第二. TCP/IP 第三. 应用层:应用层.表示层.会话层 数据流层: ...

  8. 线程安全问题.md

    # 线程安全问题: - 如果一个资源/变量,他对于多线程来讲,不用加锁也不会引起任何问题,则称为线程安全 - 线程不安全变量类型:list, set, dict - 线程安全变量类型: queue # ...

  9. GIT中常用的命令

    最近项目中使用到了GIT,所以记录一下GIT中常用的命令. GIT使用的客户端有Git Bash:http://code.google.com/p/msysgit/ 还有乌龟TortoiseGit:h ...

  10. GlusterFS 配置及使用

    GlusterFS集群创建 一.简介 GlusterFS概述 Glusterfs是一个开源的分布式文件系统,是Scale存储的核心,能够处理千数量级的客户端.在传统的解决 方案中Glusterfs能够 ...