• 【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("");
    	}
    }
    
  • 相关阅读:
    cookie和session
    ViewState与Session 的重要区别
    C#.Net 中ArrayList 与 Array的区别
    c#如何把文件夹压缩打包然后下载
    关于并发的处理
    const和readonly的区别
    计算某列的字符串相加sql语句
    MS SQL Server存储过程批量修改用户表所有者
    已有打开的与此命令相关联的DataReader,必须首先将它关闭
    XML与数据库
  • 原文地址:https://www.cnblogs.com/stargazer-cyk/p/12328475.html
Copyright © 2020-2023  润新知