String Problem

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

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
求循环节,并求字典序最大最小出现的次数
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
char a[];
int p[];
void getnext()
{
int i=,j=-;
p[]=-;
while(a[i]!='\0')
{
if(j==- || a[i]==a[j])
p[++i]=++j;
else j=p[j];
}
}
int check(bool flag)
{
int i=,j=,k=;
while(i<strlen(a) && j<strlen(a) && k<strlen(a))
{
int t=a[(j+k)%strlen(a)]-a[(i+k)%strlen(a)];
if(t==) k++;
else
{
if(flag)
{
if(t>) j+=k+;
else i+=k+;
}
else
{
if(t<) j+=k+;
else i+=k+;
}
if(i==j) j++;
k=;
}
}
return min(i,j);
}
int main()
{
while(scanf("%s",a)!=EOF)
{
int minn=check(true);
int maxn=check(false);
getnext();
int ans=(strlen(a)%(strlen(a)-p[strlen(a)]))==?strlen(a)/(strlen(a)-p[strlen(a)]):;
printf("%d %d %d %d\n",minn+,ans,maxn+,ans);
}
return ;
}

HDU 3374 String Proble的更多相关文章

  1. HDU 3374 String Problem (KMP+最大最小表示)

    HDU 3374 String Problem (KMP+最大最小表示) String Problem Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  2. HDU 3374 String Problem(KMP+最大/最小表示)

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

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

    做一个高产的菜鸡 传送门:HDU - 3374 题意:多组输入,给你一个字符串,求它最小和最大表示法出现的位置和次数. 题解:刚刚学会最大最小表示法,amazing.. 次数就是最小循环节循环的次数. ...

  4. HDU 3374 String Problem (KMP+最小最大表示)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=3374 [题目大意] 给出一个字符串,求出最小和最大表示是从哪一位开始的,并且输出数量. [题解] ...

  5. HDU 3374 String Problem(KMP+最大(最小)表示)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3374 题目大意:给出一个字符串,依次左移一个单位形成一堆字符串,求其字典序最小和最大的字符串需要左移多 ...

  6. hdu 3374 String Problem (kmp+最大最小表示法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3374 题目大意:输出最大和最小的是从哪一位开始的,同时输出最小循环节的个数. 这里简单介绍对字符串最小 ...

  7. hdu 3374 String Problem(最小表示法+最大表示法+kmp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3374 题意:给出一个字符串问这个字符串最小表示的最小位置在哪,还有有几个最小表示的串.最大表示的位置在 ...

  8. hdu 3374 String Problem(kmp+最小表示法)

    Problem Description Give you a string with length N, you can generate N strings by left shifts. For ...

  9. HDU - 3374:String Problem (最小表示法模板题)

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

随机推荐

  1. 【BZOJ 1588】 [HNOI2002]营业额统计

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 每天的最小波动值指的是和之前所有天的差值的绝对值中的最小值. 用set.的lower_bound函数. 每次找和他差值最小的数字就好 ...

  2. LaTeX 设置字体颜色

    本系列文章由 @YhL_Leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/50240179 需要包含宏包: \use ...

  3. LibSVM C/C++

    本系列文章由 @YhL_Leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/50179779 在LibSVM的库的sv ...

  4. 程序员之--C语言细节13(二维数组和指针,&amp;*a[i][0]的理解,数组1[e]和e[1]非常可能你没见过)

    主要内容:二维数组和指针.&*a[i][0]的理解.数组1[e]和e[1] #include <stdio.h> #define NUM_ROWS 10 #define NUM_C ...

  5. 1.Swift教程翻译系列——关于Swift

    英文版PDF下载地址http://download.csdn.net/detail/tsingheng/7480427 我本来是做JAVA的.可是有一颗折腾的心,苹果公布Swift以后就下载了苹果的开 ...

  6. 前端到后台ThinkPHP开发整站--php开发案例

    前端到后台ThinkPHP开发整站--php开发案例 总结 还是需要做几个案例,一天一个为佳,那样才能做得快. 从需求分析着手,任务体系要构建好,这样才能非常高效. 转自: 前端到后台ThinkPHP ...

  7. poj--3620--Avoid The Lakes(dfs)

    Avoid The Lakes Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Subm ...

  8. 47.使用 RequireJS 加载 AngularJS

    转自:https://www.cnblogs.com/best/tag/Angular/ AngularJS 目前的版本没有遵循 Javascript 约定的 AMD 模块化规范, 因此使用 Requ ...

  9. deque 归纳

    deque是STL里面的常见容器,它的本质是一个队列,但是与队列不同是的是,它可以两边进出. 下面是STL的一些常见操作. que.assign(beg,end) 将[beg; end)区间中的数据赋 ...

  10. BZOJ 2251 Trie树

    思路: i~n加到Trie树里 经过的边权+1 DFS一遍 搞定~ //By SiriusRen #include <cstdio> #include <cstring> #i ...