题目链接:https://vjudge.net/problem/HDU-3374

String Problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3646    Accepted Submission(s): 1507

Problem Description
Give you a string with length N, you can generate N strings by left shifts. For example let consider the string “SKYLONG”, we can generate seven strings:
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.
 
Output
Output 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
 
Author
WhereIsHeroFrom
 
Source
 
Recommend
lcy

题解:

1.求最小最大表示法,直接套。

2.怎么知道最小最大表示出现了几次呢?求最小循环节。

代码如下:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <sstream>
#include <algorithm>
using namespace std;
typedef long long LL;
const double eps = 1e-;
const int INF = 2e9;
const LL LNF = 9e18;
const int MAXN = 1e6+; char s[MAXN];
int Next[MAXN]; void get_next(char s[], int m)
{
int i, j;
j = Next[] = -;
i = ;
while(i<m)
{
while(j!=- && s[i]!=s[j]) j = Next[j];
Next[++i] = ++j;
}
} int getmin(char *s, int len, int type) //返回最小表示法的始端
{
int i = , j = , k = ;
while(i<len && j<len && k<len)
{
int t = s[(i+k)%len]-s[(j+k)%len];
if (!t) k++;
else
{
if (type*t>) i += k+;
else j += k+;
if (i==j) j++;
k = ;
}
}
return i<j?i:j;
} int main()
{
while(scanf("%s", s)!=EOF)
{
int len = strlen(s);
int minex = getmin(s, len, );
int maxex = getmin(s, len, -);
get_next(s, len);
int r = len-Next[len];
int times = len%r?:len/r; printf("%d %d %d %d\n", minex+, times, maxex+, times);
}
}

HDU3374 String Problem —— 最小最大表示法 + 循环节的更多相关文章

  1. hdu3374 String Problem 最小最大表示法 最小循环节出现次数

    #include <iostream> #include <cstring> #include <cstdio> using namespace std; int ...

  2. kuangbin专题十六 KMP&&扩展KMP HDU3347 String Problem(最小最大表示法+kmp)

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

  3. hdu String Problem(最小表示法入门题)

    hdu 3374 String Problem 最小表示法 view code#include <iostream> #include <cstdio> #include &l ...

  4. hdu3374 String Problem【最小表示法】【exKMP】

    String Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  5. hdu3374 String Problem

    地址:http://acm.hdu.edu.cn/showproblem.php?pid=3374 题目: String Problem Time Limit: 2000/1000 MS (Java/ ...

  6. HDU——4291A Short problem(矩阵快速幂+循环节)

    A Short problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  7. hdu 4291 A Short problem(矩阵+取模循环节)

    A Short problem                                                          Time Limit: 2000/1000 MS (J ...

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

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

  9. String Problem HDU - 3374(最大最小表示法+循环节)

    题意: 给出一个字符串,问这个字符串经过移动后的字典序最小的字符串的首字符位置和字典序最大的字符串的首字符的位置,和能出现多少次最小字典序的字符串和最大字典序的字符串 解析: 能出现多少次就是求整个字 ...

随机推荐

  1. [配置Cordova环境] [Alfred使用手册]

    Mac神器 Alfred使用手册http://www.tuicool.com/articles/YJJv2i 配置Cordova环境 1.到nodejs官网下载最新版本,安装pkg文件 2.终端运行 ...

  2. uva 1426 离散平方根

    1426 - Discrete Square Roots Time limit: 3.000 seconds A square root of a number x <tex2html_verb ...

  3. K大数查询(bzoj 3110)

    Description 有N个位置,M个操作.操作有两种,每次操作如果是1 a b c的形式表示在第a个位置到第b个位置,每个位置加入一个数c如果是2 a b c形式,表示询问从第a个位置到第b个位置 ...

  4. ADO:防止更新的数据含有单引号而出错

    原文发布时间为:2008-08-01 -- 来源于本人的百度文章 [由搬家工具导入] public void Update( string au_lname, string zip,string au ...

  5. SQL行转列 (及EAV模型获取数据)

    参考文章: http://www.williamsang.com/archives/1508.html 情景简介 学校里面记录成绩,每个人的选课不一样,而且以后会添加课程,所以不需要把所有课程当作列. ...

  6. 让Mac OS X专用高速移动硬盘在Linux下也能被读写

    MacBook Pro以及iMac等设备都具备雷电接口和USB 3.0接口,配合使用Mac OS X格式化的专用高速移动硬盘读写数据都非常快.那么这种硬盘可以在Linux下被读写吗?其实,Mac OS ...

  7. BZOJ——1202: [HNOI2005]狡猾的商人

    http://www.lydsy.com/JudgeOnline/problem.php?id=1202 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: ...

  8. luogu P1043 数字游戏

    题目描述 丁丁最近沉迷于一个数字游戏之中.这个游戏看似简单,但丁丁在研究了许多天之后却发觉原来在简单的规则下想要赢得这个游戏并不那么容易.游戏是这样的,在你面前有一圈整数(一共n个),你要按顺序将其分 ...

  9. phpQuery用法总结

    项目下载地址:http://code.google.com/p/phpquery/ 获取内容的方法: 第一种:newDocumentFile phpQuery::newDocumentFile($ur ...

  10. Loadrunner IP欺骗

    一.为什么要设置IP欺骗 1. 当某个IP的訪问过于频繁,或者訪问量过大时,server会拒绝訪问请求.这时候通过IP欺骗能够添加訪问频率和訪问量,以达到压力測试的效果. 2. 某些server配置了 ...