zoukankan      html  css  js  c++  java
  • toj 3019 Hidden Password (最小表示法)

    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

  • 相关阅读:
    蒟蒻的sb对拍方法
    LuoguP5176 公约数 题解
    天守阁的地板 题解
    Crash的数字表格 / JZPTAB 题解
    于神之怒加强版 简要题解
    最小公倍数之和 题解
    莫比乌斯反演的计算
    YY的GCD 题解
    acwing 309装饰围栏 大致思路 (预览)
    错排问题(预览)
  • 原文地址:https://www.cnblogs.com/luotinghao/p/3410389.html
Copyright © 2011-2022 走看看