题目链接: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. LA 4728 旋转卡壳算法求凸包的最大直径

    #include<iostream> #include<cstdio> #include<cmath> #include<vector> #includ ...

  2. 【BZOJ2002】弹飞绵羊(LCT)

    题意:给定一棵树,要求维护以下操作: 1.删除连接(x,y)的边 2.将(x,y)之间连边 3.询问某点子树大小 对于100%的数据n<=200000,m<=100000 思路:第一道有加 ...

  3. Python入门--13--递归

    什么是递归: 有调用函数自身的行为 有一个正确的返回条件 设置递归的深度: import sys sys.setrecursionlimit(10000) #可以递归一万次 用普通的方法也就是非递归版 ...

  4. CentOS配置TFTP服务器

    服务器端 软件包 tftp-server 启动脚本 /usr/sbin/in.tftpd 启动服务 /usr/lib/systemd/system/tftp.service 配置文件 /etc/xin ...

  5. WAMP本地环境升级php版本--第二次尝试

    wamp 环境下 php5.6.25 升级php7.1.17 实践 本文参考:https://www.cnblogs.com/hubaohua1588/p/6884146.html来进行操作. 1.从 ...

  6. Lucene 6.5.0 入门Demo

    Lucene 6.5.0 要求jdk 1.8 1.目录结构: 2.数据库环境: private int id; private String name; private float price; pr ...

  7. Compose

    安装与卸载 Compose 支持 Linux.macOS.Windows 10 三大平台. Compose 可以通过 Python 的包管理工具 pip 进行安装,也可以直接下载编译好的二进制文件使用 ...

  8. javafx中多场景的切换

    0.前言 前段时间在做javafx的应用程序,遇到一些坑.以本文记录之.(如有更好的解决办法欢迎评论,本人小白,轻喷) 1.问题 按照官方的中文文档,成功的运行了单一界面的表单登录.于是想自己试试多界 ...

  9. leetCode 65.Valid Number (有效数字)

    Valid Number  Validate if a given string is numeric. Some examples: "0" => true " ...

  10. Linux系统调用(syscall)原理(转)

    引言:分析Android源码的过程中,要想从上至下完全明白一行代码,往往涉及app.framework.native一直到kernel,可能迷失到代码世界,明白了系统调用原理,或许能帮你峰回路转,找到 ...