String Problem

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

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
题意:给你一字符串,问最小字典序还有最大字典序的最小下标,以及包含最小字典序和最大字典序的串的开始的不同下标个数。
不知道动不动就TLE什么鬼……
 #include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm> using namespace std; const int maxn = 1e6+; char s[maxn*], str[maxn];
int Next[maxn], len; void Getnext(char s[])
{
int j, k;
j = ;
k = Next[] = -;
while(j < len)
{
while(k != - && s[j] != s[k])
k = Next[k];
Next[++j] = ++k;
}
} int Getmax(char s[]) // 最大最小表示法
{
int i, j;
i = ;
j = ;
while(i < len && j < len)
{
int k = ;
while(s[i+k] == s[j+k] && k < len)
k++;
if(k == len)
break; if(s[i+k] > s[j+k])
{
if(j+k > i)
j = j+k+;
else
j = i + ;
}
else
{
if(i+k > j)
i = i + k + ;
else
i = j + ;
}
}
return min(i, j);
} int Getmin(char s[])
{
int i, j;
i = ;
j = ;
while(i < len && j < len)
{
int k = ;
while(s[i+k] == s[j+k] && k < len)
k++;
if(k == len)
break;
if(s[i+k] < s[j+k])
{
if(j+k > i)
j = j+k+;
else
j = i + ;
}
else
{
if(i+k > j)
i = i + k + ;
else
i = j + ;
}
}
return min(i, j);
} int main()
{
while(gets(str))
{
len = strlen(str);
strcpy(s, str);
strcat(s, str); memset(Next, , sizeof(Next)); Getnext(str);
int t = , k = len - Next[len]; // k 最小循环节的长度,最小循环节,神奇的东西…… if(len % k == )
t = len / k;
printf("%d %d %d %d\n", Getmin(s)+, t, Getmax(s)+, t);
}
return ;
}

写代码你就好好写代码………………………………………………………………………………………………

String Problem的更多相关文章

  1. hdu String Problem(最小表示法入门题)

    hdu 3374 String Problem 最小表示法 view code#include <iostream> #include <cstdio> #include &l ...

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

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

  3. 【HDU3374】 String Problem (最小最大表示法+KMP)

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

  4. HDOJ3374 String Problem 【KMP】+【最小表示法】

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

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

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

  6. String Problem hdu 3374 最小表示法加KMP的next数组

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

  7. ACM-ICPC2018南京赛区 Mediocre String Problem

    Mediocre String Problem 题解: 很容易想到将第一个串反过来,然后对于s串的每个位置可以求出t的前缀和它匹配了多少个(EXKMP 或者 二分+hash). 然后剩下的就是要处理以 ...

  8. hdu3374 String Problem【最小表示法】【exKMP】

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

  9. hdu 5772 String problem 最大权闭合子图

    String problem 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5772 Description This is a simple pro ...

  10. bestcoder 48# wyh2000 and a string problem (水题)

    wyh2000 and a string problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K ...

随机推荐

  1. 32 kill不掉的语句

    32 kill不掉的语句 在mysql中有两个kill命令:一个是kill query+线程id,表示终止这个线程正在执行的语句:一个是kill connection+线程id,缺省connectio ...

  2. unity不规则按钮解决方案

    一种是alpha检测 一种是设置collider 参考: https://zhuanlan.zhihu.com/p/34204396 下面给出第二种方案代码 ///按钮多边形点击方案,注意Canvas ...

  3. github创建仓库,往github上上传自己的项目

    k第一步: 在github上创建仓库 第二步: 创建一个新的项目,填写项目名称,描述 创建完成之后,跳转到下面的页面,下面红框中的网址要记住,在后面上传代码的时候需要使用 这个地址必须要记住!!! 第 ...

  4. 关于addEventListener中事件函数的this指向问题

    看代码: //定义一个可见的盒子用于绑定点击事件 var box = document.getElementById('box'); box.x = 'box' //设置执行函数的对象属性 funct ...

  5. linux复杂命令

    1,查看包含zypper且不包含ar的进程信息的2,3,8,9列信息 ps -ef|grep zypper|grep -v ar|awk '{print $2,$3,$8,$9}' eg:查看包含zy ...

  6. Sql Server主副本和辅助副本间账号同步以及权限同步

    问题描述 SqlServer如果配置了AlwaysOn,其数据库账号信息同步会出现问题. 我遇到的情况是在主副本添加了账号信息,且给某个数据库添加了权限,这个账号会同步至辅助副本,但是数据库角色信息没 ...

  7. select,poll 和 epoll ??

    其实所有的 I/O 都是轮询的方法,只不过实现的层面不同罢了. 其中 tornado 使用的就是 epoll 的. selec,poll 和 epoll 区别总结 基本上 select 有 3 个缺点 ...

  8. Knight Moves (双向bfs)

    # 10028. 「一本通 1.4 例 3」Knight Moves [题目描述] 编写一个程序,计算一个骑士从棋盘上的一个格子到另一个格子所需的最小步数.骑士一步可以移动到的位置由下图给出. [算法 ...

  9. 最全的 Java 知识总结- Github 日增 10 star

    项目地址: 如果觉得有帮助,希望大家给个 star 鼓励以下:同时也希望大家多多 fork,一起加入进来. 为什么选择做这个开源项目 首先,希望提高自己:因为选择做这个,自己肯定就会花时间去提高自己的 ...

  10. linux基础开发软件安装 - java相关

    1.linux在线安装mysql:转自 https://www.cnblogs.com/bigbrotherer/p/7241845.html ,写的很好,简单易用. 开启远程访问:转 https:/ ...