zoukankan      html  css  js  c++  java
  • cogs696 longest prefix

    cogs696 longest prefix


    原题链接


    IOI1996原题?
    其实这题我不会。
    map+string+手动氧气大法好
    //就是这么皮(滑稽


    Code

    // It is made by XZZ
    #include<cstdio>
    #include<algorithm>
    #include<map>
    #include<string>
    #include<iostream>
    #define Fname "prefix"
    #pragma GCC optimize(2)
    using namespace std;
    #define rep(a,b,c) for(rg int a=b;a<=c;a++)
    #define drep(a,b,c) for(rg int a=b;a>=c;a--)
    #define erep(a,b) for(rg int a=fir[b];a;a=nxt[a])
    #define il inline
    #define rg register
    #define vd void
    typedef long long ll;
    il int gi(){
        rg int x=0;rg char ch=getchar();
        while(ch<'0'||ch>'9')ch=getchar();
        while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
        return x;
    }
    map<string,bool>Map;
    bool f[200010];
    int main(){
        freopen(Fname".in","r",stdin);
        freopen(Fname".out","w",stdout);
        string s,S("%");
        while(cin>>s,s!=".")Map[s]=1;
        while(cin>>s)S+=s;
        int len=S.size()-1;
        int p=1;
        while((p<=len)&&(Map.find(S.substr(1,p))==Map.end()))++p;
        f[0]=f[p]=1;
        if(p==len+1){puts("0");return 0;}
        int ans=p;
        rep(i,p+1,len)rep(j,max(i-10,0),i-1)if(f[j]&&Map.find(S.substr(j+1,i-j))!=Map.end()){f[i]=1,ans=i;break;}
        printf("%d
    ",ans);
        return 0;
    }
    
  • 相关阅读:
    2016年3月3日
    性能测试之我解
    Vim命令合集
    vi-vim常用命令
    架构的本质是
    网站三层架构学习之一 分层式结构
    Spring 4 + Quartz 2.2.1 Scheduler Integration Example
    “城市民族工作条例”详解--建议废止
    字符串匹配处理
    LogBack简易教程
  • 原文地址:https://www.cnblogs.com/xzz_233/p/7545775.html
Copyright © 2011-2022 走看看