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 题意:给出一个字符串问这个字符串最小表示的最小位置在哪,还有有几个最小表示的串.最大表示的位置在 ...
随机推荐
- $python虚拟化运行环境——virtualenv
介绍 virtualenv是一种虚拟化环境,可以理解为创建了一个虚拟化的pyhon运行空间,可以从新安装各种库,而与本机环境互不影响,互相隔离. 安装及使用 首先要安装包管理工具pip(pip的使用详 ...
- linux命令(6/9):watch命令
watch是一个非常实用的命令,基本所有的Linux发行版都带有这个小工具,如同名字一样,watch可以帮你监测一个命令的运行结果,省得你一遍遍的手动运行.在Linux下,watch是周期性的执行下个 ...
- rest_framework解析器组件源码流程
rest_framework解析器组件源码流程 解析器顾名思义就是对请求体进行解析.为什么要有解析器?原因很简单,当后台和前端进行交互的时候数据类型不一定都是表单数据或者json,当然也有其他类型的数 ...
- html5 canvas js(时钟)
<!doctype html> <html> <head> <title>canvas</title> </head> < ...
- 【转载】在block中使用weakSelf/strongSelf
http://blog.lessfun.com/blog/2014/11/22/when-should-use-weakself-and-strongself-in-objc-block/
- Redis 后台运行
编辑配置文件 vim {redis_home}/redis.conf 修改daemonize (默认为no,修改为yes) 启动redis{redis_home}/src/redis-server ...
- bootstrap下拉列表重置联动
/**添加&修改时--获取机柜号**/ function BindSelectJgh(jiguiColumnIdD, jiguiNumberIdD) { var jid = !jiguiCol ...
- python学习笔记(conf配置文件)
在优化自己的框架中发现一个问题 有很多参数在很多类中都要使用.是否有什么功能可以帮助优化这些功能 这里我就想到 conf配置文件.整理了下资料 总结下内容如下 #!/usr/bin/env pytho ...
- poj3683 2 -sat输出路径
tarjan缩点,拓扑排序染色输出(貌似挑战上面没有拓扑啊,而且这样写还过了= =) 主要是找s,t,d,三者之间的关系,找出合取范式这题就很容易了 #include<map> #incl ...
- socket长连接和短链接区别
短连接 连接->传输数据->关闭连接 HTTP是无状态的,浏览器和服务器每进行一次HTTP操作,就建立一次连接,但任务结束后就中断连接.短连接是指SOCKET连接后发送后接收完数据后马上断 ...