#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. 转:jquery的$(function(){})和$(document).ready(function(){}) 的区别

    原文链接:https://www.cnblogs.com/slyzly/articles/7809935.html [转载]jquery的$(function(){})和$(document).rea ...

  2. 运行vs2010,Debug时发生“无法启动程序"http://localhost:xxx",系统找不到指定文件

    网上参考回答:应该是Visual Studio不能启动浏览器导致的结果!第一种结果是没有设置默认的浏览器,第二种情况是注册表被修改了! 我的尝试: 1.在启动处点击下三角,选择“使用以下浏览器浏览” ...

  3. 使用github的srs代码,搭建 RTMP_Server

    1. 搭建RTMP服务器 1> 获取开源代码SRS. git clone https://github.com/ossrs/srs 下载源码后,按照如下文档安装https://github.co ...

  4. wordpress去掉<link rel='dns-prefetch' href='//s.w.org' />

    我们在用wordpress建站时经常会看到<link rel='dns-prefetch' href='//s.w.org' />,应该是为了从s.w.org预获取表情和头像,目的是提高网 ...

  5. blockdev命令 blkid命令 lsblk命令

    blockdev命令  blkid命令  lsblk命令 http://www.jb51.net/LINUXjishu/310389.html block相关的命令 这篇文章主要介绍了Linux bl ...

  6. Windows server 2016 支持容器 ,安装docker 搭建Ubuntu+hadoop (docker为服务器)

    一.Windows server 2016 是肯定要安装的, 关于如何启动容器功能那就是控制面板中增加与删除里面的启用了,很多地方可以百度到 二. 安装Ubuntu hadoop 等  待续 注意: ...

  7. 报错解决——Failed to load resource: the server responded with a status of 404 (Not Found) favicon.ico文件找不到

    Django项目开发完成后在本地运行没问题,但在推到服务器上后出现报错Failed to load resource: the server responded with a status of 40 ...

  8. Python3学习之路~8.2 socket简单实例 实现ssh 发送大量数据

    实例1: 利用socket模拟客户端和服务器端各自收发一次数据: #Author:Zheng Na # 客户端 import socket # 声明socket类型,同时生成socket连接对象 cl ...

  9. sqlserver2008出现数据库主体在该数据库中拥有架构,无法删除的解决方案

    当要删除数据库中的某个用户名的时候会报错 出现数据库主体在该数据库中拥有架构,无法删除的解决方案(MicrosoftSQLServer,错误:15138) 和sql server2000不同 第一:这 ...

  10. jsp在select中的option中编写if标签

    <select onchange="lxx(this)"> <option value="">全部</option> < ...