spoj LCS

解法1:后缀自动机

解法1.1用串1建后缀自动机,用串2匹配。并记录能匹配的长度。匹配成功+1,否则变为maxlen[最后fail到的位置]+1。

解法1.2串一先加,然后加入'#‘。再加串2.加串2的时候,如果新得到的节点的slink在一串,则说明出现了2次。

解法1.3.建立广义后缀自动机,用数组记录各节点出现在哪个串,在拓扑排序。然后出现2次的maxlen最大值就是。

解法2:2分+HASH。会超时。

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
#include <stack>
#include <bitset>
//#include <unordered_set>
#define mkp make_pair
#define err cout<<"here"<<endl
using namespace std;
const double EPS=1e-12;
typedef long long lon;
typedef unsigned long long ull;
typedef map<ull,int>::iterator IT;
const lon SZ=500010,SSZ=120,APB=26,mod=97,one=1;
const lon INF=0x7FFFFFFF;
int n,cnt,nex[SZ][APB],fail[SZ];
int maxlen[SZ],minlen[SZ],trans[SZ][APB],slink[SZ];
struct nd{
    int to,wt;
    nd(int a=0,int b=0):to(a),wt(b){}
};
char ch1[SZ],ch2[SZ];

int add(int pre,int cur)
{
    int z=++cnt;
    int u=pre;
    for(;u!=-1&&!trans[u][cur];u=slink[u])
    {
        trans[u][cur]=z;
    }
    if(u==-1)
    {
        maxlen[z]=maxlen[pre]+1;
        minlen[z]=1;
        slink[z]=0;
    }
    else
    {
        int x=trans[u][cur];
        if(maxlen[x]==maxlen[u]+1)
        {
            maxlen[z]=maxlen[pre]+1;
            minlen[z]=maxlen[x]+1;
            slink[z]=x;
        }
        else
        {
            int y=++cnt;
            memcpy(trans[y],trans[x],sizeof(trans[x]));
            maxlen[y]=maxlen[u]+1;
            minlen[y]=maxlen[slink[x]]+1;
            slink[y]=slink[x];
            maxlen[x]=maxlen[x];
            minlen[x]=maxlen[y]+1;
            slink[x]=y;
            maxlen[z]=maxlen[pre]+1;
            minlen[z]=maxlen[y]+1;
            slink[z]=y;
            for(;u!=-1&&trans[u][cur]==x;u=slink[u])
            {
                trans[u][cur]=y;
            }
        }
    }
    return z;
}

void init()
{
    cin>>ch1+1>>ch2+1;
    int pre=0;
    slink[0]=-1;
    for(int i=1;ch1[i];++i)
    {
        pre=add(pre,ch1[i]-'a');
    }
}

int get_nex(int sta,int c,int &len)
{
    int u=sta;
    if(trans[u][c])
    {++len;
        return trans[u][c];
    }
    for(;u!=-1&&!trans[u][c];)
    {
        u=slink[u];
        //if(u!=-1)len=min(len,maxlen[u]);
    }
    if(u==-1)u=0,len=0;
    else len=maxlen[u]+1,u=trans[u][c];
    return u;
}

void work()
{
    int cur=0,res=0,len=0;
    for(int i=1;ch2[i];++i)
    {
        int c=ch2[i]-'a';
        cur=get_nex(cur,c,len);
        res=max(res,len);
        //cout<<len<<endl;
    }
    cout<<res<<endl;
}

void release()
{
    
}

int main()
{
    std::ios::sync_with_stdio(0);
    //freopen("d:\\1.txt","r",stdin);
    int casenum;
    //cin>>casenum;
    //cout<<casenum<<endl;
    //for(int time=1;time<=casenum;++time)
    //for(int time=1;cin>>ch+1,ch[1]!='e';++time)
    {
        init();
        work();
        release();
    }
    return 0;
}
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
#include <stack>
#include <bitset>
//#include <unordered_set>
#define mkp make_pair
#define err cout<<"here"<<endl
using namespace std;
const double EPS=1e-12;
typedef long long lon;
typedef unsigned long long ull;
typedef map<ull,int>::iterator IT;
const lon SZ=1000010,SSZ=120,APB=27,mod=97,one=1;
const lon INF=0x7FFFFFFF;
int n,cnt,num,nex[SZ][APB],fail[SZ],ans;
int maxlen[SZ],minlen[SZ],trans[SZ][APB],slink[SZ];
struct nd{
    int to,wt;
    nd(int a=0,int b=0):to(a),wt(b){}
};
char ch1[SZ],ch2[SZ];
bool ok;

int add(int pre,int cur)
{
    int z=++cnt;
    int u=pre;
    for(;u!=-1&&!trans[u][cur];u=slink[u])
    {
        trans[u][cur]=z;
    }
    if(u==-1)
    {
        maxlen[z]=maxlen[pre]+1;
        minlen[z]=1;
        slink[z]=0;
    }
    else
    {
        int x=trans[u][cur];
        if(maxlen[x]==maxlen[u]+1)
        {
            maxlen[z]=maxlen[pre]+1;
            minlen[z]=maxlen[x]+1;
            slink[z]=x;
            if(ok&&x<=num)ans=max(ans,maxlen[x]);
        }
        else
        {
            int y=++cnt;
            memcpy(trans[y],trans[x],sizeof(trans[x]));
            maxlen[y]=maxlen[u]+1;
            minlen[y]=maxlen[slink[x]]+1;
            slink[y]=slink[x];
            maxlen[x]=maxlen[x];
            minlen[x]=maxlen[y]+1;
            slink[x]=y;
            maxlen[z]=maxlen[pre]+1;
            minlen[z]=maxlen[y]+1;
            slink[z]=y;
            for(;u!=-1&&trans[u][cur]==x;u=slink[u])
            {
                trans[u][cur]=y;
            }
            if(ok&&x<=num)ans=max(ans,maxlen[y]);
        }
    }
    return z;
}

void init()
{
    cin>>ch1+1>>ch2+1;
    int pre=0;
    slink[0]=-1;
    for(int i=1;ch1[i];++i)
    {
        pre=add(pre,ch1[i]-'a');
    }
    pre=add(pre,26);
    ok=1;
    num=cnt;
    for(int i=1;ch2[i];++i)
    {
        pre=add(pre,ch2[i]-'a');
    }
    cout<<ans<<endl;
}

void work()
{
    
}

void release()
{
    
}

int main()
{
    std::ios::sync_with_stdio(0);
    //freopen("d:\\1.txt","r",stdin);
    int casenum;
    //cin>>casenum;
    //cout<<casenum<<endl;
    //for(int time=1;time<=casenum;++time)
    //for(int time=1;cin>>ch+1,ch[1]!='e';++time)
    {
        init();
        work();
        release();
    }
    return 0;
}
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
#include <stack>
#include <bitset>
//#include <unordered_set>
#define mkp make_pair
#define err cout<<"here"<<endl
using namespace std;
const double EPS=1e-12;
typedef long long lon;
typedef unsigned long long ull;
typedef map<ull,int>::iterator IT;
const lon SZ=1000010,SSZ=120,APB=27,mod=97,one=1;
const lon INF=0x7FFFFFFF;
int n,cnt,nex[SZ][APB],fail[SZ];
int maxlen[SZ],minlen[SZ],trans[SZ][APB],slink[SZ];
struct nd{
    int to,wt;
    nd(int a=0,int b=0):to(a),wt(b){}
};
char ch1[SZ],ch2[SZ];
int sta[SZ],in[SZ];

int add(int pre,int cur,int num)
{
    if(trans[pre][cur])
    {
        int u=trans[pre][cur];
        if(maxlen[u]==maxlen[pre]+1)
        {
            sta[u]|=1<<num;
            return u;
        }
        else
        {
            int z=++cnt;
            memcpy(trans[z],trans[u],sizeof(trans[u]));
            maxlen[z]=maxlen[pre]+1;
            slink[z]=slink[u];
            slink[u]=z;
            minlen[z]=maxlen[slink[z]]+1;
            minlen[u]=maxlen[z]+1;
            sta[z]|=1<<num;
            return z;
        }
    }
    int z=++cnt;
    int u=pre;
    for(;u!=-1&&!trans[u][cur];u=slink[u])
    {
        trans[u][cur]=z;
    }
    if(u==-1)
    {
        maxlen[z]=maxlen[pre]+1;
        minlen[z]=1;
        slink[z]=0;
    }
    else
    {
        int x=trans[u][cur];
        if(maxlen[x]==maxlen[u]+1)
        {
            maxlen[z]=maxlen[pre]+1;
            minlen[z]=maxlen[x]+1;
            slink[z]=x;
        }
        else
        {
            int y=++cnt;
            memcpy(trans[y],trans[x],sizeof(trans[x]));
            sta[y]=sta[x];
            maxlen[y]=maxlen[u]+1;
            minlen[y]=maxlen[slink[x]]+1;
            slink[y]=slink[x];
            maxlen[x]=maxlen[x];
            minlen[x]=maxlen[y]+1;
            slink[x]=y;
            maxlen[z]=maxlen[pre]+1;
            minlen[z]=maxlen[y]+1;
            slink[z]=y;
            for(;u!=-1&&trans[u][cur]==x;u=slink[u])
            {
                trans[u][cur]=y;
            }
        }
    }
    sta[z]|=1<<num;
    return z;
}

void topo()
{
    for(int i=1;i<=cnt;++i)
    {
        ++in[slink[i]];
    }
    queue<int> q;
    for(int i=1;i<=cnt;++i)
    {
        if(in[i]==0)
        {
            q.push(i);
        }
    }
    for(;q.size();)
    {
        int fr=q.front();
        q.pop();
        int x=slink[fr];
        --in[x];
        sta[x]|=sta[fr];
        if(in[x]==0&&x)
        {
            q.push(x);
        }
    }
}

void init()
{
    cin>>ch1+1>>ch2+1;
    int pre=0;
    slink[0]=-1;
    for(int i=1;ch1[i];++i)
    {
        pre=add(pre,ch1[i]-'a',0);
    }
    pre=0;
    for(int i=1;ch2[i];++i)
    {
        pre=add(pre,ch2[i]-'a',1);
    }
    topo();
}

void work()
{
    int res=0;
    for(int i=1;i<=cnt;++i)
    {
        if(sta[i]==3)res=max(res,maxlen[i]);
    }
    cout<<res<<endl;
}

void release()
{
    
}

int main()
{
    std::ios::sync_with_stdio(0);
    //freopen("d:\\1.txt","r",stdin);
    int casenum;
    //cin>>casenum;
    //cout<<casenum<<endl;
    //for(int time=1;time<=casenum;++time)
    //for(int time=1;cin>>ch+1,ch[1]!='e';++time)
    {
        init();
        work();
        release();
    }
    return 0;
}
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
#include <stack>
#include <bitset>
//#include <unordered_set>
#define mkp make_pair
#define err cout<<"here"<<endl
using namespace std;
const double EPS=1e-12;
typedef long long lon;
typedef unsigned long long ull;
typedef map<ull,int>::iterator IT;
const lon SZ=250010,SSZ=120,APB=26,mod=97,one=1;
const lon INF=0x7FFFFFFF;
int n;
struct nd{
    int to,wt;
    nd(int a=0,int b=0):to(a),wt(b){}
};
char ch1[SZ],ch2[SZ];
ull arr[SZ];

bool chk(int x)
{
    vector<ull> st;
    ull cur=0;
    for(int i=1;ch1[i];++i)
    {
        if(i<=x)
        {
            cur=cur*mod+ch1[i];
        }
        else
        {
            cur=cur-arr[x-1]*ch1[i-x];
            cur=cur*mod+ch1[i];
        }
        if(i>=x)st.push_back(cur);
    }
    cur=0;
    sort(st.begin(),st.end());
    for(int i=1;ch2[i];++i)
    {
        if(i<=x)
        {
            cur=cur*mod+ch2[i];
        }
        else
        {
            cur=cur-arr[x-1]*ch2[i-x];
            cur=cur*mod+ch2[i];
        }
        if(i>=x&&*lower_bound(st.begin(),st.end(),cur)==cur)return 1;
    }
    return 0;
}

void init()
{
    //cin>>ch1+1>>ch2+1;
    scanf(" %s %s",ch1+1,ch2+1);
    int len=strlen(ch1+1);
    arr[1]=mod;
    for(int i=2;i<len+5;++i)
    {
        if(i&1)arr[i]=arr[i/2]*arr[i/2]*mod;
        else arr[i]=arr[i/2]*arr[i/2];
    }
    int lo=1,hi=strlen(ch1+1)+1;
    for(;lo<hi;)
    {
        int mid=(lo+hi)/2;
        bool ok=chk(mid);
        if(ok)lo=mid+1;
        else hi=mid;
    }
    cout<<lo-1<<endl;
}

void work()
{
    
}

void release()
{
    
}

int main()
{
    //std::ios::sync_with_stdio(0);
    //freopen("d:\\1.txt","r",stdin);
    int casenum;
    
    //cin>>casenum;
    //cout<<casenum<<endl;
    //for(int time=1;time<=casenum;++time)
    //for(int time=1;cin>>ch+1,ch[1]!='e';++time)
    {
        init();
        work();
        release();
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/gaudar/p/10805234.html

基于SSM框架的智能家政保洁预约系统,是一个旨在提高家政保洁服务预约效率和管理水平的平台。该系统通过集成现代信息技术,为家政公司、家政服务人员和消费者提供了一个便捷的在线预约和管理系统。 系统的主要功能包括: 1. **用户管理**:允许消费者注册、登录,并管理他们的个人资料和预约历史。 2. **家政人员管理**:家政服务人员可以注册并更新自己的个人信息、服务类别和服务时间。 3. **服务预约**:消费者可以浏览不同的家政服务选项,选择合适的服务人员,并在线预约服务。 4. **订单管理**:系统支持订单的创建、跟踪和管理,包括订单的确认、完成和评价。 5. **评价系统**:消费者可以在家政服务完成后对服务进行评价,帮助提高服务质量和透明度。 6. **后台管理**:管理员可以管理用户、家政人员信息、服务类别、预约订单以及处理用户反馈。 系统采用Java语言开发,使用MySQL数据库进行数据存储,通过B/S架构实现用户与服务的在线交互。系统设计考虑了不同用户角色的需求,包括管理员、家政服务人员和普通用户,每个角色都有相应的权限和功能。此外,系统还采用了软件组件化、精化体系结构、分离逻辑和数据等方法,以便于未来的系统升级和维护。 智能家政保洁预约系统通过提供一个集中的平台,不仅方便了消费者的预约和管理,也为家政服务人员提供了一个展示和推广自己服务的机会。同时,系统的后台管理功能为家政公司提供了强大的数据支持和决策辅助,有助于提高服务质量和管理效率。该系统的设计与实现,标志着家政保洁服务向现代化和网络化的转型,为管理决策和控制提供保障,是行业发展中的重要里程碑。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值