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 ...
随机推荐
- 2015.1.31 DataGridView自动滚动到某行
方法一.dv.CurrentCell = dv.Rows[i].Cells[2] 但此cell不能是隐藏cell 方法二. if (dgr.Index < dv_sel_aw.FirstDisp ...
- 2015.1.8 Left join 左连接
格式 select f1.a, f2.b form f1 left jion f2 on .... 注意:左边的查询部分只能有select和from,不能出现where order by等.若有必须在 ...
- 第四章 Javac编译原理(待续)
Javac是什么 Javac编译器的基本结构 Javac工作原理分析 设计模式解析之访问者模式
- 问题:C#根据生日计算属相;结果:C#实现根据年份计算生肖属相的方法
这篇文章主要介绍了C#实现根据年份计算生肖属相的方法,涉及C#数组与字符串的操作技巧,具有一定参考借鉴价值,需要的朋友可以参考下 本文实例讲述了C#实现根据年份计算生肖属相的方法.分享给大家供大家 ...
- python 2.7.5升级到3.4.x
wget https://www.python.org/ftp/python/3.4.3/Python-3.4.3.tgz .tgz cd Python-/ Python ./configure ma ...
- canvas,绘制七巧板
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- Java was started but returned exit code=13 问题解决
我在安装完jdk后,也对环境进行了配置,且环境的配置是没有问题的.最后我下载了eclipse,然后打开之后就发现了以下图所示的错误: Java was started but returned exi ...
- hive like 模糊匹配
类似: 在MYSQL里面我们可以这样的执行SQL select a.Community,a.PID,b.spidertime,b.comm,b.showings,b.room from lianjia ...
- apache server和tomcat集群配置二:垂直负载
垂直负载就是同一个机器中的不同服务器之间的负载.跟水平负载(ip不一样的服务器之间的负载)的最大区别就是要修改tomcat的端口号,避免引起冲突. 还要注意apache中workers.propert ...
- 第5章 选举模式和ZooKeeper的集群安装 5-2 单机伪分布式安装zookeeper集群
先搭建伪分布式集群,再去搭建真分布式集群.有些的人的电脑内存.性能比较低,所以在搭建真实的一个分布式环境的话,可能会相对来说比较卡,所以两种都会做一下,首先会在单机上搭建一个集群.单机上的集群主要就是 ...