HDU 3374 String Proble
String Problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3183 Accepted Submission(s): 1295
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.
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.
#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的更多相关文章
- 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+最大/最小表示)
String Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- HDU - 3374 String Problem (kmp求循环节+最大最小表示法)
做一个高产的菜鸡 传送门:HDU - 3374 题意:多组输入,给你一个字符串,求它最小和最大表示法出现的位置和次数. 题解:刚刚学会最大最小表示法,amazing.. 次数就是最小循环节循环的次数. ...
- 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 题目大意:给出一个字符串,依次左移一个单位形成一堆字符串,求其字典序最小和最大的字符串需要左移多 ...
- 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 题意:给出一个字符串问这个字符串最小表示的最小位置在哪,还有有几个最小表示的串.最大表示的位置在 ...
- 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 (最小表示法模板题)
Give you a string with length N, you can generate N strings by left shifts. For example let consider ...
随机推荐
- 【BZOJ 1257】[CQOI2007]余数之和
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] k%i=k-(k/i)i 则∑k%i = nk-∑(k/i)*i 因为k/i是整除运算. 所以会有某一段连续的i,它们的k/i的值都 ...
- 多线程相互排斥--mutex
多线程之线程同步Mutex (功能与Critial Sections同样,可是属于内核对象,訪问速度较慢.能够被不同进程调用) 一 Mutex 相互排斥对象(mutex)内核对象可以确保线程拥 ...
- Perfect Rectangle(完美矩形)
我们有 N 个与坐标轴对齐的矩形, 其中 N > 0, 判断它们是否能精确地覆盖一个矩形区域. 每个矩形用左下角的点和右上角的点的坐标来表示.例如, 一个单位正方形可以表示为 [1,1,2,2] ...
- HDU 5310 Souvenir
Souvenir Accepts: 901 Submissions: 2743 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262 ...
- nginx 1.5 支持websocket
proxy_pass http://backend; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set ...
- SharePoint Search之(七)Search result- 结果源
在使用搜索引擎的时候.非常多情况下,用户希望限定一下搜索范围,以便更加easy找到想要的结果. watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvU1BGYXJ ...
- 20.计算速度最快的valarray
#include <string> #include <iostream> //用于计算,计算的性能高于vector与array #include <valarray&g ...
- package & import
/* * package:声明源文件所在的包,写在程序的第一行. * 每“.”一次,表示一层文件目录. * 包名都要小写. * * import: * 1)显式导入指定包下的类或接口 * 2)写在包的 ...
- PostgreSQL Replication之第一章 理解复制概念(2)
1.2不同类型的复制 现在,您已经完全地理解了物理和理论的局限性,可以开始学习不同类型的复制了. 1.2.1 同步和异步复制 我们可以做的第一个区分是同步复制和异步复制的区别. 这是什么意思呢?假设我 ...
- 《剑指offer》旋转数组的最小数字
一.题目描述 把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转. 二.输入描述 输入一个递增排序的数组的一个旋转 三.输出描述 输出旋转数组的最小元素 例如: 例如数组{3,4,5,1 ...