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. 从0开发3D引擎(八):准备“搭建引擎雏形”

    大家好,现在开始本系列的第三部分,按照以下几个步骤来搭建引擎雏形: 1.分析引擎的需求 2.实现最小的3D程序 3.从中提炼引擎原型 4.一步一步地对引擎进行改进,使其具备良好的架构 5.实现与架构相 ...

  2. arch_遇到的问题

    archlinux安装 wiki安装 可以参考这个来安装 $如果你跟我一样是用校园网安装的$ 记得使用pppoe-setup 来联网 arclinux 图形界面安装 参考 kde图形安装 需要创建一个 ...

  3. NIO&AIO编程模型

    NIO线程模型 什么是NIO线程模型? 上图是NIO的线程模型,  基于select实现,   这种线程模型的特点:  多条channel通过一个选择器和单挑线程绑定, 并且在这种编程模型中, Cha ...

  4. 对Hadoop分布式文件系统HDFS的操作实践

    原文地址:https://dblab.xmu.edu.cn/blog/290-2/ Hadoop分布式文件系统(Hadoop Distributed File System,HDFS)是Hadoop核 ...

  5. c#数字图像处理(一)Bitmap类、 Bitmapdata类和 Graphics类

    Bitmap类. Bitmapdata类和 Graphics类是C#图像处理中最重要的3个类,如果要用C#进行图像处理,就一定要掌握它们. 1.1 Bitmap类Bitmap对象封装了GDI+中的一个 ...

  6. Python3基础之正则表达式

    正则表达式 在线测试工具 http://tool.chinaz.com/regex/ 同一个位置上可以出现的字符的范围. 字符组 : [字符组] 在同一个位置可能出现的各种字符组成了一个字符组,在正则 ...

  7. Linux 常用工具openssh之ssh-add

    前言 ssh-add命令是把专用密钥添加到ssh-agent的高速缓存中,从而提高ssh的认证速度 语法 ssh-add [-cDdLlXx] [-t life] [file ...] 选项 -D:删 ...

  8. Dwz/Jquery--使用Ajax提交表单时调用表单设置的校验

    案例 今天有一个需求就是点击按钮时,使用ajax方式提交表单,而且不是直接用form表单下的submit按钮提交,表单中用的校验是dwz 自带的校验方式,表单模板如下: <li><d ...

  9. Arduino系列之光照传感器(三)

    今天,我将简单做一个当光照值低于某个值的时候,灯光自动打开,当高于某个值的时候,自动关闭. 设计代码原理: 首先,定义一个全局变量,并赋予初始值 然后,初始化程序 将设定某个IO口为输出模式 读取光度 ...

  10. FFMPEG学习----使用SDL播放YUV数据

    命令行下配置: G:\Coding\Video\SDL\proj>tree /F 文件夹 PATH 列表 卷序列号为 0FD5-0CC8 G:. │ sdl.cpp │ SDL2.dll │ S ...