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. Krypton Suite of .NET WinForms Controls

    The Krypton Suite of .NET WinForms controls are now freely available for use in personal or commeric ...

  2. sql 语句 的一些优化小总结

    1.用exists 代替 in 原理:exists 是存在一个即返回一个 而in是做全盘扫描得出所有条件内的数据 (高效) and exists (select 'x' from Person whe ...

  3. 第二次java面试(用友山东济南分公司)

    坐标:山东潍坊公共实训基地 面试单位:用友济南分公司(来了一位HR和技术经理) 本人状态:距离离校15天 宣讲: 1.女HR和男技术经理来到我们专业提前准备好的教室,先宣传海报和发传单,然后看了4个3 ...

  4. P1522 牛的旅行 (Floyd)

    [题目描述] 请编程找出一条连接两个不同牧场的路径,使得连上这条路径后,这个更大的新牧场有最小的直径.输出在所有牧场中最小的可能的直径. [题目链接] https://www.luogu.org/pr ...

  5. 年月日联动select下拉菜单

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. 搜索---BFS

    搜索   深度优先搜索和广度优先搜索广泛的应用于树和图中,但是他们的应用远不止于此. BFS   广度优先搜索一层一层地进行遍历,每层遍历都是以上一层遍历的结果作为起点,遍历一个距离能访问到的所有节点 ...

  7. ssh传文件

    #coding=utf-8 import paramiko transport = paramiko.Transport(('192.168.70.129',22)) transport.connec ...

  8. NGUI的HUD Text的扩展插件学习--(HUDText)的使用

    一,我们先添加一个空的游戏对象,在菜单中找到这个添加空的游戏对象 二,然后我们给该对象添加HUDText,然后给这个添加字体 三,我们添加个脚本,代码如下: using UnityEngine; us ...

  9. javascript中slice(),splice(),split(),substring(),substr()使用方法

    因为本人在使用这些方法时常有混淆,特总结如下: 1.slice(): Array和String对象都有 在Array中  slice(i,[j]) i为开始截取的索引值,负数代表从末尾算起的索引值,- ...

  10. Ionic -v1初始项目结构

    界面