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. IOS开发的哪些异常之异常断点

    从Android开发的异常报错到IOS的异常闪退,经历了不一样的处理过程.对于IOS的异常报错刚開始总是非常茫然,永远仅仅告诉你有异常.然后就跳到main.m文件,却不曾我告诉她在那出现.真是吊人胃口 ...

  2. QtWebkit里RenderLayer树的绘制具体流程分析

           更新:RenderLayer树的绘制对RenderObject的绘制.同一时候补足绘制阶段的描写叙述.        QtWebkit里,QWebView,QWebPage和QWebFr ...

  3. 海思 3520D 移植Qt4.5.3 一

    一.移植Qt4.5.3  1.获得 Qt4.5.3 的源码Qt4.5.3源码的原始包 qt-embedded-opensource-src-4.5.3.tar.gz 将其复制到 /opt 下,     ...

  4. sass03 变量、样式导入

    demo1.scss @import "css.css"; //导入css文件 @import "http://ss/xx"; //导入css文件 @impor ...

  5. angularjs 服务供应商

    <!DOCTYPE HTML> <html ng-app="myApp"> <head> <meta http-equiv="C ...

  6. nyoj--1011--So Easy[II](数学几何水题)

    So Easy[II] 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描述 这是一道基础的计算几何问题(其实这不提示大家也都看的出).问题描述如下: 给你一个N边形.且N边形 ...

  7. 从Git里拉取远程的所有分支

    从Git里拉取远程的所有分支 git branch -r | grep -v '\->' | while read remote; do git branch --track "${r ...

  8. win10安装jdk8 配置环境变量

    参考:https://jingyan.baidu.com/article/6b97984dd257b41ca2b0bf86.html  

  9. PostgreSQL Replication之第二章 理解PostgreSQL的事务日志(3)

    2.3 理解一致性和数据丢失 挖掘PostgreSQL事务日志而不考虑一致性是不可能的.在本章的第一部分,我们已经大体上解释了事务日志的基本思想.您已经知道,无需事先的日志改变的能力,使数据处于一种好 ...

  10. UVa 202 Repeating Decimals【模拟】

    题意:输入整数a和b,输出a/b的循环小数以及循环节的长度 学习的这一篇 http://blog.csdn.net/mobius_strip/article/details/39870555 因为n% ...