kuangbin专题十六 KMP&&扩展KMP HDU3347 String Problem(最小最大表示法+kmp)
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.
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 只知道最小最大表示法。但是名次没思路。 后来看题解是循环节。。。。
脑子真是废了。。 循环节用next数组搞定 即可
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn=;
char s[maxn],t[maxn];
int Next[maxn],len; void prekmp(char* s) {
int i,j;
j=Next[]=-;
i=;
while(i<len) {
while(j!=-&&s[i]!=s[j]) j=Next[j];
if(s[++i]==s[++j]) Next[i]=Next[j];
else Next[i]=j;
}
} int getmin(char* str) {
int len2=strlen(str);
int i=,j=,k=;
while(i<len&&j<len&&k<len) {
int tmp=s[(i+k)%len2]-s[(j+k)%len2];
if(!tmp) k++;
else {
if(tmp<) j+=k+;
else i+=k+;
if(i==j) j++;
k=;
}
}
return min(i,j);
} int getmax(char* str) {
int len2=strlen(str);
int i=,j=,k=;
while(i<len&&j<len&&k<len) {
int tmp=s[(i+k)%len2]-s[(j+k)%len2];
if(!tmp) k++;
else {
if(tmp<) i+=k+;
else j+=k+;
if(i==j) j++;
k=;
}
}
return min(i,j);
} int main() {
while(~scanf("%s",s)) {
len=strlen(s);
prekmp(s);
int num=,len1=len-Next[len];
if(len%len1==)
num=len/len1;
strcpy(t,s);
strcat(s,t);
printf("%d %d %d %d\n",getmin(s)+,num,getmax(s)+,num);
}
}
kuangbin专题十六 KMP&&扩展KMP HDU3347 String Problem(最小最大表示法+kmp)的更多相关文章
- kuangbin专题十六 KMP&&扩展KMP HDU2609 How many (最小字符串表示法)
Give you n ( n < 10000) necklaces ,the length of necklace will not large than 100,tell me How man ...
- kuangbin专题十六 KMP&&扩展KMP HDU2328 Corporate Identity
Beside other services, ACM helps companies to clearly state their “corporate identity”, which includ ...
- kuangbin专题十六 KMP&&扩展KMP HDU1238 Substrings
You are given a number of case-sensitive strings of alphabetic characters, find the largest string X ...
- kuangbin专题十六 KMP&&扩展KMP HDU3336 Count the string
It is well known that AekdyCoin is good at string problems as well as number theory problems. When g ...
- kuangbin专题十六 KMP&&扩展KMP POJ3080 Blue Jeans
The Genographic Project is a research partnership between IBM and The National Geographic Society th ...
- kuangbin专题十六 KMP&&扩展KMP HDU3746 Cyclic Nacklace
CC always becomes very depressed at the end of this month, he has checked his credit card yesterday, ...
- kuangbin专题十六 KMP&&扩展KMP HDU2087 剪花布条
一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图案.对于给定的花布条和小饰条,计算一下能从花布条中尽可能剪出几块小饰条来呢? Input输入中含有一些数据,分别是成对出现的花布条和小 ...
- kuangbin专题十六 KMP&&扩展KMP HDU1686 Oulipo
The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e ...
- kuangbin专题十六 KMP&&扩展KMP HDU1711 Number Sequence
Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], ...... , b[M] (1 <= M ...
随机推荐
- nginx 限制solr
server { listen 80; server_name bai.com www.bai.com; location /solr/ { allow 192.168.0.0/24; allow ...
- LAMP 2.1Apache不记录指定文件类型日志
访问日志只需要记地址,不用记录图片. 对无用的图片日志做标记,针对标记做限制.打开 vim /usr/local/apache2/conf/extra/httpd-vhosts.conf 把 Erro ...
- linux命令-分区表fstab
磁盘分区后需要格式化,挂载之后才能使用 我们有开机后自动挂载的需求,方法有两种 1.配置文件的形式,把mount写到配置文件里去 cat /etc/fstab 2.把挂载命令写到一个文件里 ls /e ...
- DAY4-函数进阶
目录: 一.迭代器 二.生成器 三.面向过程编程 四.三元表达式.列表推导式.生成器表达式 五.第归与二分法 六.匿名函数 七.内置函数 练习 一.迭代器 一.迭代的概念 #迭代器即迭代的工具,那什么 ...
- ElasticSearch入门一
ElasticSearch入门一 1 安装ElasticSearch,配置环境变量,并且存在Java环境,而且是Java环境: 下图是安装的目录: 进入bin目录之后,请看bin目录: 启动elast ...
- PHP处理密码的几种方式
在 PHP中,经常会对用户身份进行认证.本文意在讨论对密码的处理,也就是对密码的加密处理. 1.MD5 相信很多PHP开发者在最先接触PHP的时候,处理密码的首选加密函数可能就是MD5了,我当时就是这 ...
- PHP自定义函数获取汉字首字母的方法
使用场景:城市列表等根据首字母排序的场景 function getFirstCharter($str) { if (empty($str)) { return ''; } $fchar = ord($ ...
- Mybatis避免出现语法错
在使用MyBatis的时候,可能会看起来没有问题,但是代码运行的时候出现意想不到的错误. 看如下代码: <update id="updateByPrimaryKeySelective& ...
- 11.PowerSploit攻击指南
本人小白,写这篇文章主要记录一下自己的PowerShell学习之路,大牛请绕道:https://www.anquanke.com/subject/id/90541 首先PowerShell的攻击工具有 ...
- chrome安装postman插件
参考http://www.cnplugins.com/zhuanti/how-to-make-crx-install.html 下载地址:http://www.cnplugins.com/down/p ...