hdu3374 kmp+最小表示法
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+最小表示法的更多相关文章
- hdu-3374(kmp+最小表示法)
题意:给你一个字符串,这个字符串我们可以把把他变成n个字符串按照以下规则:将当前字符串第一个放到字符串最后一位,字符串的下标依次向前推一位,比如:s[1] s[2 ]s[3] s[4]->s[2 ...
- hdu5442(2015长春赛区网络赛1006)后缀数组+KMP /最小表示法?
题意:给定一个由小写字母组成的长度为 n 的字符串,首尾相连,可以从任意一个字符开始,顺时针或逆时针取这个串(长度为 n),求一个字典序最大的字符串的开始字符位置和顺时针或逆时针.如果有多个字典序最大 ...
- hdu 3374 String Problem(kmp+最小表示法)
Problem Description Give you a string with length N, you can generate N strings by left shifts. For ...
- hdu3374 最大最小表示法 +kmp
#include <iostream> #include <algorithm> #include <string.h> #include <cstdio&g ...
- hdu3374最小表示法+KMP
题意: 给你一个最长100W的串,然后让你找到最小同构子串,还有最大同构子串的下标,最小同构子串就是把字符串连接成一个环,然后选择一个地方断开,得到的一个ASCII最小的子串(求最大同理) ...
- hdu3374 String Problem KMP+最大最小表示法
Give you a string with length N, you can generate N strings by left shifts. For example let consider ...
- HDU-3374-String Problem(最小表示法, KMP)
链接: https://vjudge.net/problem/HDU-3374 题意: Give you a string with length N, you can generate N stri ...
- 【KMP】【最小表示法】NCPC 2014 H clock pictures
题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1794 题目大意: 两个无刻度的钟面,每个上面有N根针(N<=200000),每个 ...
- Manacher模板,kmp,扩展kmp,最小表示法模板
*N]; //储存临时串 *N];//中间记录 int Manacher(char tmp[]) { int len=strlen(tmp); ; ;i<len;i++) { s[cnt++]= ...
随机推荐
- JavaScript中hoisting(悬置/置顶解析/预解析) 实例解释,全局对象,隐含的全局概念
JavaScript中hoisting(悬置/置顶解析/预解析) 实例解释,全局对象,隐含的全局概念 <html> <body> <script type="t ...
- java copy 文件夹
import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io ...
- MySQL Crash Course #16# Chapter 24. Using Cursors + mysql 循环
mysql中游标的使用案例详解(学习笔记)这篇讲得相当直白好懂了. 索引: cursor 基础讲解 mysql 循环 书上的整合代码 cursor 基础讲解 cursor 有点类似于 JDBC 中的 ...
- Unable to load the Wrapper's native library because none of the following files及解决方法
在有几个应用中,在启动的时候发现下列警告: The version of the script (3.5.29) doesn't match the version of this Wrapper ( ...
- 20165211 2017-2018-2 《Java程序设计》第7周学习总结
20165211 2017-2018-2 <Java程序设计>第7周学习总结 教材学习内容总结 本周,我学习了书本上第十一章的内容,以下是我整理的主要知识. 第十一章 JDBC和MySQL ...
- Cron表达式详解和表达式的验证
本篇不算原创,因为主要内容来自网上的博客,所以给出我参考文章的链接. 本文cron表达式详解的大部分内容参考了[cron表达式详解]和Quartz使用总结.Cron表达式 这两篇文章. cron校验的 ...
- 在Visual C#中使用XML指南之读取XML
网站:http://www.yesky.com/155/1915155all.shtml#p1915155
- Python3基础 os listdir 列举指定的所有文件及文件夹的名字
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Go第十篇之反射
反射是指在程序运行期对程序本身进行访问和修改的能力.程序在编译时,变量被转换为内存地址,变量名不会被编译器写入到可执行部分.在运行程序时,程序无法获取自身的信息. 支持反射的语言可以在程序编译期将变量 ...
- NOIP2018 退役记
NOIP挂完,OI再见 AFO Day 0 早上的高铁,1点多到广州,2点多到酒店,下午就是颓颓颓,然后晚上随便刷了一下板子,反正PJ也没啥板子可以刷 就这样浪费了一天,我到底在干嘛 Day 1 早上 ...