zoukankan      html  css  js  c++  java
  • UVA 1314 最小表示法

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=36117

    题意:给定长度为n的字符串,求一个起点使字符串从该起点起的字符串字典序最小

    思路:最小表示法模板题

    #define _CRT_SECURE_NO_DEPRECATE
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<cmath>
    #include<algorithm>
    #include<vector>
    using namespace std;
    const int MAXN = 100000 + 5;
    typedef long long int LL;
    #define INF 0x3f3f3f3f
    int MinRepresentation(char *s){
        int i = 0, j = 1, k = 0, l = strlen(s);
        while (i < l&&j < l&&k < l){
            int li, lj;
            li = (i + k) >= l ? i + k - l : i + k;
            lj = (j + k) >= l ? j + k - l : j + k;
            if (s[li] == s[lj]){
                k++;
            }
            else{
                if (s[li]>s[lj]){
                    i = i + k + 1;
                }
                else{
                    j = j + k + 1;
                }
                if (i == j){
                    j++;
                }
                k = 0;
            }
        }
        return i < j ? i : j;
    }
    char str[MAXN];
    int main()
    {
        int n,t;
        scanf("%d", &t);
        while (t--){
            scanf("%d", &n);
            scanf("%s", str);
            printf("%d
    ", MinRepresentation(str));
        }
        return 0;
    }
  • 相关阅读:
    OutputStream (字节流写出)
    Reader(字符流读取)
    InputStream (字节流读取)
    File
    IO简介
    BigDecimal
    SimpleDateFormat
    Date和Calendar
    包装类
    本地与远程对应分支,本地建立分支,修改代码, 上传到远程对应的分支
  • 原文地址:https://www.cnblogs.com/kirito520/p/5606743.html
Copyright © 2011-2022 走看看