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

  • 相关阅读:
    计算机网络-TCP的三次握手与四次挥手
    计算机网络-XSS及CSRF攻击防御
    计算机网络-HTTP与HTTPS的区别
    装饰器模式和代理模式的区别
    23种设计模式总结
    单例模式详解
    常用设计模式总结
    PG-用户|角色管理
    PG-表空间管理
    TiDB-性能测试
  • 原文地址:https://www.cnblogs.com/luotinghao/p/3410389.html
Copyright © 2011-2022 走看看