地址:http://acm.hdu.edu.cn/showproblem.php?pid=3374

题目:

String Problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3029    Accepted Submission(s): 1230

Problem Description
Give you a string with length N, you can generate N strings by left shifts. For example let consider the string “SKYLONG”, we can generate seven strings:
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.
 
Input
  Each line contains one line the string S with length N (N <= 1000000) formed by lower case letters.
 
Output
Output four integers separated by one space, 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
 
Author
WhereIsHeroFrom
 
Source
 
Recommend
lcy
 
思路:最大最小表示法
 #include <bits/stdc++.h>

 using namespace std;

 #define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=2e6+;
const int mod=1e9+; int nt[K];
char sa[K];
void kmp_next(char *T,int *next)
{
next[]=;
for(int i=,j=,len=strlen(T);i<len;i++)
{
while(j&&T[i]!=T[j]) j=next[j-];
if(T[i]==T[j]) j++;
next[i]=j;
}
}
int kmp(char *S,char *T,int *next)
{
int ans=;
int ls=strlen(S),lt=strlen(T);
kmp_next(T,next);
for(int i=,j=;i<ls;i++)
{
while(j&&S[i]!=T[j]) j=next[j-];
if(S[i]==T[j]) j++;
if(j==lt) ans++;
}
return ans;
}
//ff为真表示最小,为假表示最大
int mx_mi_express(char *S,bool ff,int len)
{
int i=,j=,k;
while(i<len&&j<len)
{
k=;
while(k<len&&S[i+k]==S[j+k]) k++;
if(k==len) return i<=j?i:j;
if((ff&&S[i+k]>S[j+k]) || (!ff&&S[i+k]<S[j+k]))
{
if(i+k+>j) i=i+k+;
else i=j+;
}
else if((ff&&S[i+k]<S[j+k]) || (!ff&&S[i+k]>S[j+k]))
{
if(j+k+>i) j=j+k+;
else j=i+;
}
}
return i<=j?i:j;
}
int main(void)
{
int t,n;cin>>t;
while(scanf("%s",sa)==)
{
kmp_next(sa,nt);
int len=strlen(sa);
int num=len-nt[len-];
if(num!=len&&len%num==)num=len/num;
else num=;
for(int i=;i<len;i++)
sa[i+len]=sa[i];
printf("%d %d %d %d\n",+mx_mi_express(sa,,len),num,+mx_mi_express(sa,,len),num);
}
return ;
}

hdu3374 String Problem的更多相关文章

  1. HDU3374 String Problem —— 最小最大表示法 + 循环节

    题目链接:https://vjudge.net/problem/HDU-3374 String Problem Time Limit: 2000/1000 MS (Java/Others)    Me ...

  2. hdu3374 String Problem【最小表示法】【exKMP】

    String Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  3. hdu3374 String Problem KMP+最大最小表示法

    Give you a string with length N, you can generate N strings by left shifts. For example let consider ...

  4. hdu3374 String Problem 最小最大表示法 最小循环节出现次数

    #include <iostream> #include <cstring> #include <cstdio> using namespace std; int ...

  5. 【HDU3374】 String Problem (最小最大表示法+KMP)

    String Problem Description Give you a string with length N, you can generate N strings by left shift ...

  6. (KMP 最大表示最小表示)String Problem -- hdu-- 3374

    http://acm.hdu.edu.cn/showproblem.php?pid=3374 String Problem Time Limit: 2000/1000 MS (Java/Others) ...

  7. hdu String Problem(最小表示法入门题)

    hdu 3374 String Problem 最小表示法 view code#include <iostream> #include <cstdio> #include &l ...

  8. HDU 3374 String Problem(KMP+最大/最小表示)

    String Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  9. HDOJ3374 String Problem 【KMP】+【最小表示法】

    String Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

随机推荐

  1. C++之类模板

    C++之类模板 代码如下:  C++ Code  123456789101112131415161718192021222324252627282930313233343536373839404142 ...

  2. Struts2_day01--课程安排_Struts2概述_入门

    Struts2_day01 Struts2课程安排 今天内容 Struts2概述 Struts2框架入门 导入源文件 Struts2执行过程 查看源代码 Struts2的核心配置文件 标签packag ...

  3. Dubbo+Zookeeper视频教程

    http://www.roncoo.com/course/view/f614343765bc4aac8597c6d8b38f06fd#boxTwo

  4. mybatis设置数据库连接的密码不需要加密

    mybatis设置数据库连接的密码不需要加密:在数据库连接配置处加上:<property name="connectionProperties" value="co ...

  5. PAT 甲级 1068 Find More Coins(0,1背包)

    1068. Find More Coins (30) 时间限制 150 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Eva l ...

  6. 剖析Docker文件系统:Aufs与Devicemapper

    http://www.infoq.com/cn/articles/analysis-of-docker-file-system-aufs-and-devicemapper Docker镜像 典型的Li ...

  7. 设计模式之Singleton模式

    当程序运行时,有时会希望在程序中,只能存在一个实例,为了达到目的,所以设计了Singleton模式,即单例模式. 单例模式的特征: 想确保任何情况下只存在一个实例 想在程序上表现出只存在一个实例 示例 ...

  8. 用Nginx反向代理Node.js

    安装pm2 npm install pm2 -g ln -s /home/download/node-v8.11.1-linux-x64/lib/node_modules/pm2/bin/pm2 /u ...

  9. mysql主从同步出现异常语句跳过错误处理

    1.跳过操作: mysql>slave stop; mysql>SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1 跳过一个事务 mysql>slave st ...

  10. pandas_datareader.data 和 fix_yahoo_finance 获取金融数据

    参考:https://zhuanlan.zhihu.com/p/35360694 1.获取数据 #定义所需要的数据 gafataDict={"谷歌":"GOOG" ...