• 【BZOJ4641】—基因改造(Kmp)


    传送门
    bzojbzoj关了,干脆别开了 ,只有darkbzojdarkbzoj

    这道题和这道有区别???

    #include<bits/stdc++.h>
    using namespace std;
    const int RLEN=1<<20|1;
    inline char gc(){
        static char ibuf[RLEN],*ib,*ob;
        (ob==ib)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
        return (ob==ib)?EOF:*ib++;
    }
    inline int read(){
        char ch=gc();
        int res=0,f=1;
        while(!isdigit(ch))f^=ch=='-',ch=gc();
        while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
        return f?res:-res;
    }
    #define ll long long
    #define re register
    #define pii pair<int,int>
    #define fi first
    #define se second
    #define pb push_back
    #define cs const
    #define bg begin
    #define poly vector<int>
    #define chemx(a,b) ((a)<(b)?(a)=(b):0)
    #define chemn(a,b) ((a)>(b)?(a)=(b):0)
    cs int N=1000005;
    int fail[N],T,c,last[N];
    int a[N],b[N],v[N],n,m,ans[N],tot;
    inline bool comp(int a,int b,int l){
    	return (a==b)||(a>l&&b>l);
    }
    int main(){
    	T=read(),c=read();
    	while(T--){
    		n=read(),m=read(),tot=0;
    		for(int i=1;i<=n;i++)v[i]=read();
    		memset(last,0,sizeof(int)*(c+1));
    		for(int i=1;i<=n;i++)a[i]=i-last[v[i]],last[v[i]]=i;
    		for(int i=1;i<=m;i++)v[i]=read();
    		memset(last,0,sizeof(int)*(c+1));
    		for(int i=1;i<=m;i++)b[i]=i-last[v[i]],last[v[i]]=i;
    		for(int i=0,j=2;j<=m;j++){
    			while(i&&!comp(b[i+1],b[j],i))i=fail[i];
    			if(comp(b[i+1],b[j],i))i++;
    			fail[j]=i;
    		}
    		for(int i=0,j=1;j<=n;j++){
    			while(i&&!comp(b[i+1],a[j],i))i=fail[i];
    			if(comp(b[i+1],a[j],i))i++;
    			if(i==m)ans[++tot]=j-i+1,i=fail[i];
    		}
    		cout<<tot<<'
    ';
    		for(int i=1;i<=tot;i++)cout<<ans[i]<<" ";puts("");
    	}
    }
    
  • 相关阅读:
    数据库pubs
    当前目录中查找特定类型的文件
    DBHelper,ADO直接操作数据库,扩展DataTable操作数据裤的方法
    行记录次序+等差数列
    面试的通用要求
    zoj_3367Connect them
    hdoj_4198Quick out of the Harbour
    Win32常见异常
    hdoj_1026Ignatius and the Princess I
    移动 II
  • 原文地址:https://www.cnblogs.com/stargazer-cyk/p/12328474.html
Copyright © 2020-2023  润新知