博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU3374 String Problem —— 最小最大表示法 + 循环节
阅读量:4941 次
发布时间:2019-06-11

本文共 2045 字,大约阅读时间需要 6 分钟。

题目链接:

 

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.怎么知道最小最大表示出现了几次呢?求最小循环节。

 

代码如下:

1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 using namespace std;13 typedef long long LL;14 const double eps = 1e-6;15 const int INF = 2e9;16 const LL LNF = 9e18;17 const int MAXN = 1e6+10;18 19 char s[MAXN];20 int Next[MAXN];21 22 void get_next(char s[], int m)23 {24 int i, j;25 j = Next[0] = -1;26 i = 0;27 while(i
0) i += k+1;44 else j += k+1;45 if (i==j) j++;46 k = 0;47 }48 }49 return i
View Code

 

转载于:https://www.cnblogs.com/DOLFAMINGO/p/7894883.html

你可能感兴趣的文章
程序员怎么写出一份漂亮的简历
查看>>
HDU-2067-小兔的棋盘
查看>>
磁盘分区需要知道的概念
查看>>
升序排序例子1——comparator
查看>>
关于在IBatis中返回DataSet
查看>>
python3--匿名函数
查看>>
iOS连续上传多张图片
查看>>
RN animated缩放动画
查看>>
PowerDesigner物理模型生成Excel文件
查看>>
pyqt多文件打包
查看>>
PHP字符串处理函数
查看>>
stm32新建工程(详细)
查看>>
【Codeforces】Gym 101173B Bipartite Blanket 霍尔定理+状压DP
查看>>
HDU - 1757 A Simple Math Problem (矩阵快速幂)
查看>>
python学习记录
查看>>
MySQL 之 视图、触发器、存储过程、函数、事物与数据库锁
查看>>
算法第五章作业
查看>>
Linux常用命令总结
查看>>
HDU 1257 最少拦截系统【最长上升子序列】
查看>>
FIFO的使用场景
查看>>