Hidden Password

时间限制(普通/Java):1000MS/3000MS 运行内存限制:65536KByte
总提交: 53 测试通过: 19

描述

Some time the programmers have very strange ways to hide their passwords. See
for example how Billy "Hacker" Geits hide his password. Billy chooses a string S
composed of small Latin letters with length L. Then he makes all L-1 one-letter
left cyclic shifts of the string and takes as a password one prefix of the
lexicographically first of the obtained strings (including S). For example let
consider the string alabala. The cyclic one-letter left shifts (including the
initial string) are:

alabala
labalaa
abalaal
balaala
alaalab
laalaba
aalabal

and lexicographically first of them is the string aalabal. The first letter
of this string is in position 6 in the initial string (the positions in the
string are counted from 0).

Write a program that for given string S finds the start position of the
smallest lexicographically one-letter left cyclic shift of this string. If the
smallest lexicographically left shift appears more than once then the program
have to output the smallest initial position.

输入

Your program has to be ready to solve more than one test case. The first line
of the input file will contains only the number T of the test cases. Each of the
following T lines will describe one test case - first the length L of the string
(5 <= L <= 100000) and then, separated by one space, the string S
itself.

输出

The output file have to
contain exactly T lines with a single number each - the initial position found
by your program.

样例输入

2
6 baabaa
7 alabala

样例输出

1
6

题目来源

Southeastern Europe 2003

最小表示法 学习资料:

http://blog.csdn.net/cclsoft/article/details/5467743

模板 & 练习:

http://hi.baidu.com/matrush/item/9e06d33ba1c38bb6124b1427

toj 3019 Hidden Password (最小表示法)的更多相关文章

  1. [USACO5.5]隐藏口令Hidden Password [最小表示法模板]

    最小表示法就是一个字符串构成一个环,找以哪个点为开头字典序最小. 然后我们就可以用n2的算法愉快的做啦~实际上有O(n)的做法的,就是用两个指针扫,如果这两个位置的字典序相等,就一起往后,如果某一个大 ...

  2. 洛谷P1709 [USACO5.5]隐藏口令Hidden Password(最小表示法)

    题目描述 有时候程序员有很奇怪的方法来隐藏他们的口令.Binny会选择一个字符串S(由N个小写字母组成,5<=N<=5,000,000),然后他把S顺时针绕成一个圈,每次取一个做开头字母并 ...

  3. [洛谷P1709] [USACO5.5]隐藏口令Hidden Password

    洛谷题目链接:[USACO5.5]隐藏口令Hidden Password 题目描述 有时候程序员有很奇怪的方法来隐藏他们的口令.Binny会选择一个字符串S(由N个小写字母组成,5<=N< ...

  4. zoj 1729 Hidden Password

    Hidden Passwordhttp://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=729 Time Limit: 2 Seconds ...

  5. USACO 5.5 Hidden Password

    Hidden Password ACM South Eastern Europe -- 2003 Sometimes the programmers have very strange ways of ...

  6. HDU 4162 Shape Number (最小表示法)

    题意:给你一串n个数,求出循环来看一阶差的最小字典序:数字串看成一个顺时针的环,从某一点开始顺时针循环整个环,保证字典序最小就是答案 例如给你 2 1 3 就会得到(1-2+8 注意题意负数需要加8) ...

  7. POJ 1635 树的最小表示法/HASH

    题目链接:http://poj.org/problem?id=1635 题意:给定两个由01组成的串,0代表远离根,1代表接近根.相当于每个串对应一个有根的树.然后让你判断2个串构成的树是否是同构的. ...

  8. HDU 2609 最小表示法

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2609 题意:给定n个循环链[串],问有多少个本质不同的链[串](如果一个循环链可以通过找一个起点使得和 ...

  9. HDU 4162 最小表示法

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=4162 题意:给定一个只有0-7数字组成的串.现在要由原串构造出一个新串,新串的构造方法:相邻2个位置的数字 ...

随机推荐

  1. Miller-Rabin​素数测试算法

    \(Miller-Rabin\)​素数测试 用途 判断整数\(n\)是否是质数,在\(n\)较小的情况下,可以使用试除法,时间复杂度为\(O(\sqrt n)\).但当\(n\)的值较大的时候,朴素的 ...

  2. 多级反向代理java获取真实IP地址

    public static String getIpAddress(HttpServletRequest request){ String ip = request.getHeader("x ...

  3. .net Core Autofac稍微高级一点的方法

    前情摘要 前段时间写了autofac的注入但是每次都需要去修改startup这应该不是大家想要的. 至少不是我想要的. 网上有朋友说可以创建一个基础类来时间. 好了吹牛时间结束我们开始干点正事. 创建 ...

  4. Myeclipse 2017 下载+安装+激活+集成配置【JRE 8+Tomcat 9+MySQL 5.7.29】

    Myeclipse 2017 的下载 Myeclipse 2017 下载地址:https://www.jianguoyun.com/p/DTEBo1cQ6LnsBxj9984C Myeclipse 2 ...

  5. FluentData -Micro ORM with a fluent API that makes it simple to query a database

    Code samples Create and initialize a DbContextThe connection string on the DbContext class can be in ...

  6. BZOJ 1770 lights燈

    题目传送门 分析: 跑着去学了一波异或方程组高斯消元 (全世界就我不知道系列..) 然后我们可以列方程组诶 (a[1][x]&x[1])^(a[2][x]&x[2])^...^(a[n ...

  7. Ubuntu学习之路1

    最近重装了系统,对自己很久的win7 say goodBye.学习了自制U盘系统盘,重装了win8,然后在win8上倒腾,发现还是不错的.于是又在win8上装回了win7上的VMware,捣鼓了一下U ...

  8. livego+obs+flv.js 搭建视频直播

    一.流程 主播通过 obs软件通过直播 ->推流到->直播服务器 客户通过浏览器 访问站点->flv.js拉取直播服务器视频流并播放 二.环境 centos7 直播服务器 https ...

  9. [校内训练19_09_05]ca

    题意 对于任意1 ≤k≤N,求有多少个左右区分的恰有k个叶子节点的二叉树,满足对于每个节点要么没有叶子节点要么有两个节点,同时不存在一个叶子节点,使得根到它的路径上有不少于M条向左的边. 答案对998 ...

  10. linux--->Linux centon6.9 安装mysql

    Linux centon6.9 安装mysql 查看系统自带的安装包 yum list installed | grep mysql 2.上边显示有mysql 有5.1和5.5两个版本,我安装5.5 ...