HDU3374 String Problem —— 最小最大表示法 + 循环节
题目链接:https://vjudge.net/problem/HDU-3374
String Problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3646 Accepted Submission(s): 1507
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
题解:
1.求最小最大表示法,直接套。
2.怎么知道最小最大表示出现了几次呢?求最小循环节。
代码如下:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <sstream>
#include <algorithm>
using namespace std;
typedef long long LL;
const double eps = 1e-;
const int INF = 2e9;
const LL LNF = 9e18;
const int MAXN = 1e6+; char s[MAXN];
int Next[MAXN]; void get_next(char s[], int m)
{
int i, j;
j = Next[] = -;
i = ;
while(i<m)
{
while(j!=- && s[i]!=s[j]) j = Next[j];
Next[++i] = ++j;
}
} int getmin(char *s, int len, int type) //返回最小表示法的始端
{
int i = , j = , k = ;
while(i<len && j<len && k<len)
{
int t = s[(i+k)%len]-s[(j+k)%len];
if (!t) k++;
else
{
if (type*t>) i += k+;
else j += k+;
if (i==j) j++;
k = ;
}
}
return i<j?i:j;
} int main()
{
while(scanf("%s", s)!=EOF)
{
int len = strlen(s);
int minex = getmin(s, len, );
int maxex = getmin(s, len, -);
get_next(s, len);
int r = len-Next[len];
int times = len%r?:len/r; printf("%d %d %d %d\n", minex+, times, maxex+, times);
}
}
HDU3374 String Problem —— 最小最大表示法 + 循环节的更多相关文章
- hdu3374 String Problem 最小最大表示法 最小循环节出现次数
#include <iostream> #include <cstring> #include <cstdio> using namespace std; int ...
- kuangbin专题十六 KMP&&扩展KMP HDU3347 String Problem(最小最大表示法+kmp)
Give you a string with length N, you can generate N strings by left shifts. For example let consider ...
- hdu String Problem(最小表示法入门题)
hdu 3374 String Problem 最小表示法 view code#include <iostream> #include <cstdio> #include &l ...
- hdu3374 String Problem【最小表示法】【exKMP】
String Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu3374 String Problem
地址:http://acm.hdu.edu.cn/showproblem.php?pid=3374 题目: String Problem Time Limit: 2000/1000 MS (Java/ ...
- HDU——4291A Short problem(矩阵快速幂+循环节)
A Short problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- hdu 4291 A Short problem(矩阵+取模循环节)
A Short problem Time Limit: 2000/1000 MS (J ...
- hdu3374 String Problem KMP+最大最小表示法
Give you a string with length N, you can generate N strings by left shifts. For example let consider ...
- String Problem HDU - 3374(最大最小表示法+循环节)
题意: 给出一个字符串,问这个字符串经过移动后的字典序最小的字符串的首字符位置和字典序最大的字符串的首字符的位置,和能出现多少次最小字典序的字符串和最大字典序的字符串 解析: 能出现多少次就是求整个字 ...
随机推荐
- hdu4035 Maze (树上dp求期望)
dp求期望的题. 题意: 有n个房间,由n-1条隧道连通起来,实际上就形成了一棵树, 从结点1出发,开始走,在每个结点i都有3种可能: 1.被杀死,回到结点1处(概率为ki) 2.找到出口,走出迷宫 ...
- Spoj-DRUIDEOI Fata7y Ya Warda!
Fata7y Ya Warda! Druid (AKA Amr Alaa El-Deen) and little EOIers have finished their training and the ...
- 蜥蜴 BZOJ 1066
蜥蜴 [问题描述] 在一个r行c列的网格地图中有一些高度不同的石柱,一些石柱上站着一些蜥蜴,你的任务是让尽量多的蜥蜴逃到边界外. 每行每列中相邻石柱的距离为1,蜥蜴的跳跃距离是d,即蜥蜴可以跳到平面距 ...
- BestCoder Round #29 1003 (hdu 5172) GTY's gay friends [线段树 判不同 预处理 好题]
传送门 GTY's gay friends Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Ot ...
- 更改App名称
To change the installed application name, in Xcode: 1. Select your Target on the left side under Gro ...
- centos7 搭建hadoop
参考文档:http://blog.csdn.net/xiaoxiangzi222/article/details/52757168 https://waylau.com/centos-7-instal ...
- android Containers控件
1.RadioGroup 一组单选框容器 2.ListView 3.GridView 4.ExpandableListView 可折叠列表 5.ScrollView 上下滚动条 6.Horizonta ...
- slf4j 搭配 log4j2 处理日志
目录 关于 log4j 关于 slf4j 案例使用 关于 log4j Log4j + Slf4j 的使用组合最为常见,但是我们知道 Log4j 目前已经停止更新了.Apache推出了新的 Log4j2 ...
- 框架-数据库定义MD5加密
1.--定义Md5加密declare @pt_pwd varchar(50)set @pt_pwd = ''set @pt_pwd = substring(sys.fn_sqlvarbasetostr ...
- SQL2000数据库密码被替换,重置密码提示未能找到存储过程sp_password解决方案
利用windows身份验证进入查询分析器后在master数据库下运行如下脚本: create procedure sp_password @old sysname = NULL, -- the old ...