HDU - 3374:String Problem (最小表示法模板题)
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
#include<bits/stdc++.h>
using namespace std;
const int maxn=;
char a[maxn]; int Next[maxn],num,L;
void KMP()
{
for(int i=,j=;i<=L;i++){
while(j&&a[i]!=a[j+]) j=Next[j];
if(a[i]==a[j+]) j++;
Next[i]=j;
}
num=L%(L-Next[L])?:L/(L-Next[L]);
}
int minexpress()
{
int i=,j=,k=;
while(i<=L&&j<=L&&k<L){
int ti=(i+k>L?i+k-L:i+k);
int tj=j+k>L?j+k-L:j+k;
if(a[ti]==a[tj]) k++;
else {
if(a[ti]<a[tj]) j+=k+;
else i+=k+;
if(i==j) j++;
k=;
}
}
return min(i,j);
}
int maxexpress()
{
int i=,j=,k=;
while(i<=L&&j<=L&&k<L){
int ti=i+k>L?i+k-L:i+k;
int tj=j+k>L?j+k-L:j+k;
if(a[ti]==a[tj]) k++;
else {
if(a[ti]>a[tj]) j+=k+;
else i+=k+;
if(i==j) j++;
k=;
}
}
return min(i,j);
}
int main()
{
int T,Min,Max;
while(~scanf("%s",a+)){
L=strlen(a+);
KMP();
Min=minexpress();
Max=maxexpress();
printf("%d %d %d %d\n",Min,num,Max,num);
}
return ;
}
HDU - 3374:String Problem (最小表示法模板题)的更多相关文章
- hdu String Problem(最小表示法入门题)
hdu 3374 String Problem 最小表示法 view code#include <iostream> #include <cstdio> #include &l ...
- HDU 3374 String Problem (KMP+最大最小表示)
HDU 3374 String Problem (KMP+最大最小表示) String Problem Time Limit: 2000/1000 MS (Java/Others) Memory ...
- hdu 3374 String Problem(kmp+最小表示法)
Problem Description Give you a string with length N, you can generate N strings by left shifts. For ...
- HDU - 3374 String Problem (kmp求循环节+最大最小表示法)
做一个高产的菜鸡 传送门:HDU - 3374 题意:多组输入,给你一个字符串,求它最小和最大表示法出现的位置和次数. 题解:刚刚学会最大最小表示法,amazing.. 次数就是最小循环节循环的次数. ...
- String Problem HDU - 3374(最大最小表示法+循环节)
题意: 给出一个字符串,问这个字符串经过移动后的字典序最小的字符串的首字符位置和字典序最大的字符串的首字符的位置,和能出现多少次最小字典序的字符串和最大字典序的字符串 解析: 能出现多少次就是求整个字 ...
- HDU 3374 String Problem(KMP+最大/最小表示)
String Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- HDU 3374 String Problem
最大最小表示法与KMP求循环节 最大最小表示法 最大最小表示法与KMP求循环节的模板题, #include <iostream> #include <cstdio> #incl ...
- hdu 3374 String Problem (kmp+最大最小表示法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3374 题目大意:输出最大和最小的是从哪一位开始的,同时输出最小循环节的个数. 这里简单介绍对字符串最小 ...
- hdu 3374 String Problem(最小表示法+最大表示法+kmp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3374 题意:给出一个字符串问这个字符串最小表示的最小位置在哪,还有有几个最小表示的串.最大表示的位置在 ...
随机推荐
- ASC转换BCD,ASC2BCD(转)
int ASC2BCD(const char* szASC,byte* szBDC) { int szASCLen=strlen(szASC); byte * bpBCD = new by ...
- 利用C#查看特定服务是否安装
需求:想通过C#代码来查看IIS服务或者MSMQ是否已经安装 分析:IIS服务和MSMQ安装完成后都会创建windows服务,所以我们只需要查看对应的服务是否存在即可. 准备工作: IIS服务名称:W ...
- C++类中成员变量的初始化总结
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...
- CSS3飘带状3D菜单
在线演示 本地下载
- 20145229吴姗珊逆向BOF实践
20145229吴姗珊逆向BOF实践 实践 实践目标 本次实践的对象是一个名为pwn1的linux可执行文件 该程序正常执行流程是:main调用foo函数,foo函数会简单回显任何用户输入的字符串. ...
- 伸展树基础(Splay)
3224: Tyvj 1728 普通平衡树 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 3948 Solved: 1627 [Submit][St ...
- OSTU二值化算法
介绍 Ostu方法又名最大类间差方法,通过统计整个图像的直方图特性来实现全局阈值T的自动选取,其算法步骤为: 1) 先计算图像的直方图,即将图像所有的像素点按照0~255共256个bin,统计落在每个 ...
- 进程管理工具supervisor
1. 简介 supervisor有两个组件:supervisord和supervisorctl,组成了client/server结构. supervisord负责读入配置文件,然后supervisor ...
- struts2——多文件上传
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- java--何时处理Exception(哪一个层级),包装的基础类处理任务尽可能简洁,写入日志,检查null等运行时异常
1. 运行时异常和受检异常 2. 提前预防运行时异常.最常发生的是NPE,而检查NPE是程序员的基本职责.其他的,如除0等运行时异常的检查,需要程序员仔细检查,每个函数都得检查(除非可以确定不会有空指 ...