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. 12.instanceof和类型转换

    Instanceof: 判断一个对象是什么类型的~,可以判断两个类之间是否存在父子关系 package com.oop.demo07; public class Person { public voi ...

  2. 深入学习MySQL 01 一条查询语句的执行过程

    在学习SpringCloud的同时,也在深入学习MySq中,听着<mysql45讲>,看着<高性能MySQL>,本系列文章是本人学习过程的总结,水平有限,仅供参考,若有不对之处 ...

  3. 简单总结关于阿里云CDN的知识

    CDN概念剖析 这里解释一下几个概念,摘自阿里云官方文档. 源站: 源站决定了回源时,请求到哪个IP 回源host:回源host决定回源请求访问到该IP上的哪个站点 例子1:源站是域名 源站为 www ...

  4. Hexo+coding实现自动化部署

    前言 昨天写了一篇利于云环境写博客,但是让群里大佬们看了下.评论道:"写的不错,但还是觉得这个云环境太繁琐了,没有CI/CD自动化部署方便".于是我便百度查了下,网上文章大部分是通 ...

  5. C语言I作业1

    1 你对软件工程专业或计算机科学与技术专业了解是怎样的? 软件工程顾名思义就是工程化的方法生产软件的一门学科.涉及到程序设计语言,数据库,软件开发工具,系统平台,标准,设计模式等方面. 2 你了解c语 ...

  6. 一道面试题引发的对 Java 内存模型的一点疑问

    一道面试题引发的对Java内存模型的一点疑问 问题描述 如上图所示程序,按道理,子线程会通过 num++ 操作破坏 while 循环的条件,从而终止循环,执行最后的输出操作.但在我的多次运行中,偶尔会 ...

  7. 三、Linux系统中的文件类型和文件扩展名

    .sock文件也是一类特殊的文件,这类文件通常用在网络之间进行数据连接,如:我们可以启动一个程序来监听客户端的要求,客户端可以通过套接字来进行通信: linux中的文件类型 文件类型介绍 Linux系 ...

  8. rep stos 指令(Intel汇编)

    今天读代码时,忽然跳出如下一条指令==>> 汇编代码: rep stos dword ptr es:[edi] 在网上查了相关资料显示: /************************ ...

  9. 【OpenGL】OpenGL4.3常用指令目录

    参考OpenGL编程指南 第8版 VAO void glGenVertexArrays(GLsizei n, GLuint *arrays); 返回n个未使用的对象名到数组arrays中,用作顶点数组 ...

  10. SQLYOG导入数据时报错,出现找不到Microsoft office 元驱动程式,并且无法安装64位office Access驱动

    当我们使用mysql导入外部数据时(如Excel表),有时会出现如下的错误问题,即找不到64位access驱动.为了解决这个问题,我们需要下载相应的驱动,通过下图中的点击此链接即可进入下载页面(htt ...