String Problem
String Problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2000 Accepted Submission(s): 875
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.
#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的更多相关文章
- hdu String Problem(最小表示法入门题)
hdu 3374 String Problem 最小表示法 view code#include <iostream> #include <cstdio> #include &l ...
- HDU 3374 String Problem(KMP+最大/最小表示)
String Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- 【HDU3374】 String Problem (最小最大表示法+KMP)
String Problem Description Give you a string with length N, you can generate N strings by left shift ...
- HDOJ3374 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 String Problem (KMP+最大最小表示) String Problem Time Limit: 2000/1000 MS (Java/Others) Memory ...
- String Problem hdu 3374 最小表示法加KMP的next数组
String Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- ACM-ICPC2018南京赛区 Mediocre String Problem
Mediocre String Problem 题解: 很容易想到将第一个串反过来,然后对于s串的每个位置可以求出t的前缀和它匹配了多少个(EXKMP 或者 二分+hash). 然后剩下的就是要处理以 ...
- hdu3374 String Problem【最小表示法】【exKMP】
String Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu 5772 String problem 最大权闭合子图
String problem 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5772 Description This is a simple pro ...
- bestcoder 48# wyh2000 and a string problem (水题)
wyh2000 and a string problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K ...
随机推荐
- Krypton Suite of .NET WinForms Controls
The Krypton Suite of .NET WinForms controls are now freely available for use in personal or commeric ...
- sql 语句 的一些优化小总结
1.用exists 代替 in 原理:exists 是存在一个即返回一个 而in是做全盘扫描得出所有条件内的数据 (高效) and exists (select 'x' from Person whe ...
- 第二次java面试(用友山东济南分公司)
坐标:山东潍坊公共实训基地 面试单位:用友济南分公司(来了一位HR和技术经理) 本人状态:距离离校15天 宣讲: 1.女HR和男技术经理来到我们专业提前准备好的教室,先宣传海报和发传单,然后看了4个3 ...
- P1522 牛的旅行 (Floyd)
[题目描述] 请编程找出一条连接两个不同牧场的路径,使得连上这条路径后,这个更大的新牧场有最小的直径.输出在所有牧场中最小的可能的直径. [题目链接] https://www.luogu.org/pr ...
- 年月日联动select下拉菜单
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 搜索---BFS
搜索 深度优先搜索和广度优先搜索广泛的应用于树和图中,但是他们的应用远不止于此. BFS 广度优先搜索一层一层地进行遍历,每层遍历都是以上一层遍历的结果作为起点,遍历一个距离能访问到的所有节点 ...
- ssh传文件
#coding=utf-8 import paramiko transport = paramiko.Transport(('192.168.70.129',22)) transport.connec ...
- NGUI的HUD Text的扩展插件学习--(HUDText)的使用
一,我们先添加一个空的游戏对象,在菜单中找到这个添加空的游戏对象 二,然后我们给该对象添加HUDText,然后给这个添加字体 三,我们添加个脚本,代码如下: using UnityEngine; us ...
- javascript中slice(),splice(),split(),substring(),substr()使用方法
因为本人在使用这些方法时常有混淆,特总结如下: 1.slice(): Array和String对象都有 在Array中 slice(i,[j]) i为开始截取的索引值,负数代表从末尾算起的索引值,- ...
- Ionic -v1初始项目结构
界面