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 ...
随机推荐
- Vue中解决路由切换,页面不更新的实用方法
前言:vue-router的切换不同于传统的页面的切换.路由之间的切换,其实就是组件之间的切换,不是真正的页面切换.这也会导致一个问题,就是引用相同组件的时候,会导致该组件无法更新,也就是我们口中的页 ...
- 16/7/8_PHP-设置cookie会话控制(session与cookie)
设置cookie PHP设置Cookie最常用的方法就是使用setcookie函数,setcookie具有7个可选参数,我们常用到的为前5个: name( Cookie名)可以通过$_COOKIE[' ...
- python 正则表达式 re.sub & re.subn
Grammar: re.sub(pattern, repl, string[, count]) 使用repl替换string中每一个匹配的子串后返回替换后的字符串.当repl是一个字符串时,可以使用\ ...
- 【python+selenium自动化】使用pytest+allure2完成自动化测试报告的输出
pytest的pytest-html插件是一个很方便的测试报告,运行自动化测试用例时,pytest后加上参数即可 allure是一个测试报告的框架,相比pytest-html的优势就是“逼格” 他的优 ...
- ementUi rules表单验证 --》Wangqi
ElementUi rules表单验证 ElementUi 表单验证 工作中常用到的JS验证 可以在pattern中书写正则,并且配合elementUI进行表单验证. pattern 属性规定用于 ...
- 实验报告一 &第三周课程总结
实验报告 1.打印输出所有的“水仙花数”,所谓“水仙花数”是指一个3位数,其中各位数字立方和等于该数本身.例如,153是一个“水仙花数”. 实验代码: public class wdnmd{ publ ...
- vue项目 Request Payload改成Form Data
vue项目中提交表单时,请求参数是Request Payload时在main.js中加 axios.defaults.headers.post['Content-Type'] = 'applicati ...
- 01背包(第k优解)
Bone Collector II Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- [常用类]Number & Math 类(转载)
下面的表中列出的是 Number & Math 类常用的一些方法: 序号 方法与描述 1 xxxValue() 将 Number 对象转换为xxx数据类型的值并返回. 2 compareTo( ...
- 使用git版本管理时的免密问题
方式1 使用ssh 方式 方式2 使用命令 git config --global credential.helper store 会把密码存放到当前用户的home目录下的 该文件中 [root@ ...