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. Tesseract-OCR-v5.0中文识别,训练自定义字库,提高图片的识别效果

    1,下载安装Tesseract-OCR 安装,链接地址https://digi.bib.uni-mannheim.de/tesseract/ ​ 2,安装成功 tesseract -v 注意:安装后, ...

  2. [bzoj4417] [洛谷P3990] [Shoi2013] 超级跳马

    Description 现有一个n行m列的棋盘,一只马欲从棋盘的左上角跳到右下角.每一步它向右跳奇数列,且跳到本行或相邻行.跳越期间,马不能离开棋盘.例如,当n = 3, m = 10时,下图是一种可 ...

  3. 13、python的路径处理

    前言:本文主要介绍python中路径的处理,包括os模块和有关的2个魔法变量. 一.os模块 python里面的os模块有许多方法可以让我们通过代码实现创建,删除和更改目录,具体如下: os.getc ...

  4. 4、python基础语法

    前言:本文主要介绍python的一些基础语法,包括标识符的定义.行和缩进.引号和注释.输入输出.变量的定义. 一.标识符 1.凡是我们自己取的名字,都是标识符. 2.在Python里,标识符由字母.下 ...

  5. Matplotlib API汉化 Pyplot API

    https://www.cnblogs.com/chenxygx/p/9554443.html

  6. Java多线程:实现API接口创建线程方式详解

    先看例子: /**实现Runnable接口创建线程步骤: * 1.创建一个实现Runnable接口的类 * 2.重写Runnable类中抽象的run()方法 * 3.创建实现类的对象 * 4.声明Th ...

  7. Python PE8编程规范

    参考博客:https://blog.csdn.net/weixin_39723544/article/details/82144280 1.使用四个空格而不是tab进行缩进 2.默认使用utf-8编码 ...

  8. Mavn 项目 引入第三方jar包 导致ClassNotFoundException

    案例 我有一个Maven构建的项目,项目模块之间有依赖关系,我需要用到一个本地的jar包,而该jar包不能通过配置pom.xml文件从远程仓库自动下载,于是我直接导入该jar包到其中一个项目,不通过p ...

  9. C语言创建文件夹

    问题需求:在程序中需要使用文件夹时,一般可以先在程序目录或某一路径下创建一个文件夹,然后使用该文件夹. 这种方法比较麻烦,需提前创建文件夹. 使用C语言创建文件夹的代码可以如下: #include & ...

  10. Windows玩转Kubernetes系列3-Centos安装K8S

    以往文章参考: Windows玩转Kubernetes系列1-VirtualBox安装Centos Windows玩转Kubernetes系列2-Centos安装Docker 安装K8S yum in ...