hdu3374 String Problem
地址: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
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.
aaaaaa
ababab
1 6 1 6
1 3 2 3
- #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的更多相关文章
- HDU3374 String Problem —— 最小最大表示法 + 循环节
题目链接:https://vjudge.net/problem/HDU-3374 String Problem Time Limit: 2000/1000 MS (Java/Others) Me ...
- hdu3374 String Problem【最小表示法】【exKMP】
String Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu3374 String Problem KMP+最大最小表示法
Give you a string with length N, you can generate N strings by left shifts. For example let consider ...
- hdu3374 String Problem 最小最大表示法 最小循环节出现次数
#include <iostream> #include <cstring> #include <cstdio> using namespace std; int ...
- 【HDU3374】 String Problem (最小最大表示法+KMP)
String Problem Description Give you a string with length N, you can generate N strings by left shift ...
- (KMP 最大表示最小表示)String Problem -- hdu-- 3374
http://acm.hdu.edu.cn/showproblem.php?pid=3374 String Problem Time Limit: 2000/1000 MS (Java/Others) ...
- 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 ...
- HDOJ3374 String Problem 【KMP】+【最小表示法】
String Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
随机推荐
- Web前端设计模式--制作漂亮的弹出层
设计场景: Ben最近在负责一个购书网站,在网站的首页上,有一个叫做“最新上架”的板块,板块的内容比较简单,只有书籍名称,作者姓名和上架时间(如图),当初设计的时候并i没有过于丰富的构思... 现在问 ...
- 扩展jquery scroll事件,支持 scroll start 和 scroll stop
效果预览: github: https://besswang.github.io/webapp-scroll/ 参考地址: http://www.ghugo.com/special-scroll-ev ...
- [SDOI2016 Round1] 征途[斜率优化]
2225. [SDOI2016 Round1] 征途 ★★★☆ 输入文件:menci_journey.in 输出文件:menci_journey.out 简单对比时间限制:1 s 内存 ...
- json学习之JSONArray的应用(转载)
从json数组中得到相应java数组,如果要获取java数组中的元素,只需要遍历该数组. 1 /** 2 * 从json数组中得到相应java数组 3 * JSONArray下的toArray()方法 ...
- hibernate缓存,四种状态
FlushMode.AUTO:Hibernate判断对象属性有没有改变,是默认的清理模式 FlushMode.COMMIT:在事务结束之前清理Session的缓存,其他任何时候都不清理缓存 Flush ...
- C#中命名空间别名的使用
C#中使用命名空间来分割不同的层级,在不同的层级中可以使用相同的类声明和变量声明.在程序中使用不同命名空间的下的相同名称的类时:可以用一下这几种方法进行限定: 1.使用完全限定名 using Syst ...
- HDU_5534_Partial Tree
Partial Tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)To ...
- netty4.x 实现接收http请求及响应
参考 netty4.x 实现接收http请求及响应 - En taro tassadar - CSDN博客 https://blog.csdn.net/sinat_39783636/article/d ...
- initialize myObject by calling a function that returns an object literal
w作用域控制变量的可见范围. JavaScript: The Good Parts Instead of initializing myObject with an object literal, w ...
- Yii框架2.0 数据库操作初接触
Yii2.0和Yii1.1版本的变动还是挺多的,我发现配置文件有许多不同,Yii1.1版本里有个main.php 好多信息是在这里配置的,比如默认控制器,数据库连接信息:Yii的数据库配置被单独拿出来 ...