zoukankan      html  css  js  c++  java
  • ping(NOIP模拟赛Round 4)第一次程序Rank 1!撒花庆祝!~(≧▽≦)/~

    题目:

     

    恩,就是裸的字符串处理啦。

    连标程都打的是暴力(随机数据太水啦!吐槽。)

    本来O(n^2q)TLE好吧。、

    然后我发明了一种神奇的算法,随机数据跑的很快!,当然最坏复杂度跟标程一样啦。

    不过期望复杂度是O(nq)是不是很快

    好吧说下我的做法,

    我用computer数组储存字符串,用iter[i]表示长度为i的字符串一共有几个

    sum[i][j]表示长度为i的第j个字符串。。

    所以就像哈希一样。。

    第一次跑的比标程快!O(∩_∩)O~~

    下面贴代码

    #include<iostream> 
    #include<cstdio> 
    #include<cstring> 
    using namespace std; 
    int sum[21][3001]; 
    int iter[3001],total=0; 
    char computer[3001][21]; 
    bool openq[3001]; 
    int ans=0; 
    int q; 
    int main(){ 
        //freopen("ping.in","r",stdin); 
        //freopen("ping.out","w",stdout); 
        scanf("%d",&q); 
        for(int i=1;i<=q;i++) 
        { 
            char mingling[4]; 
            scanf("%s",mingling); 
            if(mingling[0]=='S') 
            { 
                char qaq[21]; 
                scanf("%s",qaq); 
                int find; 
                int changdu=strlen(qaq);             
                for(int j=1;j<=iter[changdu];j++) 
                { 
                    bool cunzai=true; 
                    for(int k=0;k<changdu;k++) 
                        if(computer[sum[changdu][j]][k]!=qaq[k]){cunzai=false;break;} 
                    if(cunzai){find=sum[changdu][j];break;}   
                } 
                openq[find]=false;       
            } 
            else if(mingling[0]=='O') 
            { 
                char qaq[21]; 
                scanf("%s",qaq); 
                int find; 
                bool cunzai=false;           
                int changdu=strlen(qaq); 
                for(int j=1;j<=iter[changdu];j++) 
                { 
                    cunzai=true; 
                    for(int k=0;k<changdu;k++) 
                        if(computer[sum[changdu][j]][k]!=qaq[k]){cunzai=false;break;} 
                    if(cunzai){find=sum[changdu][j];break;}  
                } 
                if(!cunzai){ 
                    total++; 
                    for(int j=0;j<changdu;j++) 
                    computer[total][j]=qaq[j];   
                    sum[changdu][++iter[changdu]]=total; 
                    openq[total]=true; 
                } 
                else openq[find]=true; 
            }    
            else if(mingling[0]=='P') 
            { 
                char qaq[21]; 
                scanf("%s",qaq); 
                int changdu=strlen(qaq); 
                for(int j=1;j<=iter[changdu];j++) 
                { 
                    if(!openq[sum[changdu][j]])continue; 
                    bool cunzai=true; 
                    for(int k=0;k<changdu;k++) 
                    { 
                        if(computer[sum[changdu][j]][k]!=qaq[k]&&qaq[k]!='?'){cunzai=false;break;} 
                    } 
                    if(cunzai)ans++; 
                } 
                printf("%d
    ",ans); 
                ans=0;  
            }    
        } 
        return 0; 
        //fclose(stdin); 
        //fclose(stdout); 
    } 
  • 相关阅读:
    爬虫之爬取淘宝主题市场主要产品信息
    Linux内核11-定时器和时间管理
    UNIX8-进程控制
    UNIX7-进程环境
    Unix3-文件I/O接口
    Linux进程-打开的文件
    递归与二叉树_leetcode230
    递归与二叉树_leetcode235
    递归与二叉树_leetcode226
    递归与二叉树_leetcode222
  • 原文地址:https://www.cnblogs.com/ghostfly233/p/6910003.html
Copyright © 2011-2022 走看看