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 ...
随机推荐
- c++调用c#代码
// ConsoleApplication1.cpp : 此文件包含 "main" 函数.程序执行将在此处开始并结束. // #include "pch.h" ...
- 自动化测试中,元素无法点击定位等问题的解决:js的使用方法
在自动化测试中经常会遇到使用selenium方法定位元素点击操作失败的情况,例如,我们想实现在浏览器输入http://www.baidu.com,进入百度首页后,鼠标悬停在“更多产品”上,点击“全部产 ...
- 重拾SQL——从无到有
2016.10.22 因为工作需要,在这里提前重拾sql. 0.创建并选择数据库 mysql> SHOW DATABASES; +--------------------+ | Database ...
- 时间同步,使用oracle自带的ctss
crsctl check ctss --observer mode cluvfy comp clocksync -检查crss为啥没启用 根据不同版本删除ntp的配置和服务 AIX: stops ...
- Hibernate的HQL多表查询
HQL的内连接查询 对于HQL内链接查询,查询的是两张表的数据,这两张表的数据首先是保存在数组之中,然后在将每一个数组保存在List集合之中进行返回 代码片段: @Test // 内连接 public ...
- C程序优化
1 优化内存使用 后期程序优化的时候看内存分配是否浪费:是否留有安全裕量:有些内存是否分配过多,有些内存是否分配了没使用:尤其是创建对象的时候
- java8 stream 用法收集
public class Test1 { public static void main(String[] args) { List<Integer> numbers = new Arra ...
- Web API入门二(实例)
学习编程的最好方法就是实例,本人用的是VS2015 1.创建ASP.NET Web空项目 点击确定后即创建了空"WebApi"项目 2.下面,我们需要使用NuGet包管理器添加最新 ...
- [LOJ2736] [JOISC 2016 Day 3] 回转寿司 (分块+堆)
[LOJ2736] [JOISC 2016 Day 3] 回转寿司 (分块+堆) 题面 给出一个有n 个点的环,环上各点有一个初始权值 \(a_i\) 给出 Q 个询问,每次询问给出一个区间 [l,r ...
- Javascript 中的深浅拷贝
工作中经常会遇到需要复制 JS 数据的时候,遇到 bug 时实在令人头疼:面试中也经常会被问到如何实现一个数据的深浅拷贝,但是你对其中的原理清晰吗?一起来看一下吧! 为什么会有深浅拷贝 想要更加透彻的 ...