zoukankan      html  css  js  c++  java
  • P1368 工艺

    题目

    P1368 工艺
    你好水题

    做法

    备份一下原数组,然后插入,直接输出贪心每位最小的就好了

    My complete code

    再见水题

    #include<map>
    #include<iostream>
    #include<algorithm>
    #include<cstdio>
    #include<cstring>
    #include<string>
    using namespace std;
    typedef int LL;
    const LL maxn=1000000;
    inline LL Read(){
    	LL x(0),f(1);char c=getchar();
    	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    	while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+c-'0',c=getchar();
    	return x*f;
    }
    LL n,nod=1,lst=1;
    LL a[maxn];
    struct SAM{
    	LL fail,len;
    	map<LL,LL> son;
    }S[maxn];
    inline void Insert(LL c){
    	LL np=++nod,p=lst; lst=nod;
    	S[np].len=S[p].len+1;
    	while(p&&S[p].son[c]==0){
    		S[p].son[c]=np;
    		p=S[p].fail;
    	}
    	if(!p)
    	    S[np].fail=1;
    	else{
    		LL q=S[p].son[c];
    		if(S[q].len==S[p].len+1)
    		    S[np].fail=q;
    		else{
    			LL nq=++nod; S[nq].len=S[p].len+1;
    			S[nq].son=S[q].son;
    			S[nq].fail=S[q].fail;
    			S[q].fail=S[np].fail=nq;
    			while(p&&S[p].son[c]==q){
    				S[p].son[c]=nq;
    				p=S[p].fail;
    			}
    		}
    	}
    }
    int main(){
    	n=Read();
    	for(LL i=1;i<=n;++i)
    	    a[i]=Read();
    	for(LL i=1;i<n;++i)
    	    a[i+n]=a[i];
    	for(LL i=1;i<2*n;++i)
    	    Insert(a[i]);
    	LL now(1);
    	for(LL i=1;i<=n;++i){
    		printf("%d ",S[now].son.begin()->first);
    		now=S[now].son.begin()->second;
    	}
    	return 0;
    }
    
  • 相关阅读:
    Spring配置文件中别名的使用
    Spring IOC容器创建对象的方式
    sass安装及使用
    word转html 压缩图片网站
    Yarn 和 Npm 命令行切换 摘录
    react生命周期
    event事件
    Flex 布局
    YYYY-mm-dd HH:MM:SS 时间格式
    页面按钮埋点+跟踪location.search
  • 原文地址:https://www.cnblogs.com/y2823774827y/p/10317546.html
Copyright © 2011-2022 走看看