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

    https://vjudge.net/contest/282991#problem/E

    别人的博客:https://wizmann.tk/minimal-round-string.html

    我自己想了一个证明方式,已经满足自己了,只不过自己证出来的东西,放在博客上怕误人子弟,要是你非要看的话。。。

    先写完那个CF的题,再看完我的代码才行

    #include<iostream>
    #include<algorithm>
    #include<vector>
    #include<stack>
    #include<queue>
    #include<map>
    #include<set>
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<ctime>
    #define fuck(x) cout<<#x<<" = "<<x<<endl;
    #define ls (t<<1)
    #define rs ((t<<1)+1)
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    const int maxn = 2000086;
    const int inf = 2.1e9;
    const ll Inf = 999999999999999999;
    const int mod = 1000000007;
    const double eps = 1e-6;
    const double pi = acos(-1);
    int n;
    char s[maxn];
    
    bool judge()
    {
        for(int i=2;i<=n;i++){
            if(s[i]<s[1]){return false;}
            else if(s[i]==s[1]){
                int k=0;
                for(int j=1;j+i<=2*n;j++,k++){
                    if(s[j]>s[i+j-1]){return false;}
                    else if(s[j]<s[i+j-1]){break;}
                }
                i+=k;
            }
        }
        return true;
    }
    
    int main()
    {
    //    ios::sync_with_stdio(false);
    //    freopen("in.txt","r",stdin);
        scanf("%d",&n);
        scanf("%s",s+1);
        for(int i=1;i<=n;i++){
            s[i+n]=s[i];
        }
        if(judge()){printf("Yes
    ");}
        else printf("No
    ");
    
        return 0;
    }
    View Code

    有  S1_S2_C1   S1_S2_C2 ;S1,S2都是相同的开头,S1在字符串首。

    j作为一个指针向后移动,如果已经移动到了第二个S1处,并且比较C1和C2的时候,发现C1<C2了,这个时候就不用把j挪到S2那里去了,因为S2早就被测过,而且是面对比C2还小的C1,他都通过了测试,那么面对C2,当然更没有问题。

  • 相关阅读:
    %2d
    将块中的文字设置成属性,即实现块中文字可拖动的功能
    获得块参照的插入点方法
    排序
    将几个实体对象变成一个块
    对克隆实体的类型转换
    对实体的克隆
    递归-顺序输出任意正整数各位
    递归-汉诺塔
    递归-最大公约数
  • 原文地址:https://www.cnblogs.com/ZGQblogs/p/10472313.html
Copyright © 2011-2022 走看看