zoukankan      html  css  js  c++  java
  • usaco-4.3-lgame-passed

    一个小错误,排查了半天,不要提早引用,需要引用能简化书写。

    /*
    ID: qq104801
    LANG: C++
    TASK: lgame
    */
    
    #include <iostream>
    #include <fstream>
    #include <cstring>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <algorithm>
    
    using namespace std;
    
    int cmp(const void* a,const void* b)
    {
        return *(string*)a > *(string*)b?1:-1;
    }
    const int  len=40000;
    FILE* ff;
    int s[26]={2,5,4,4,1,6,5,5,1,7,6,3,5,2,3,5,7,2,1,2,4,6,6,7,5,7};
    int d[26];
    string a[len];
    
    void test()
    {   
        freopen("lgame.in","r",stdin);  
        freopen("lgame.out","w",stdout);  
        ff=fopen("lgame.dict","r");
        
        int l=-1;
        string str;
        cin >>str;
        
        for(int i=0;i<str.length();i++)
            d[str[i]-'a']++;
        string ss;
        char ch[10];
        fscanf(ff,"%s",ch);ss=ch;
        while(ss!=".")
        {
            bool bb=false;
            for(int i=0;i<ss.length();i++)
                if(!d[ss[i]-'a']){bb=true;break;}
            if(!bb)a[++l]=ss;
            fscanf(ff,"%s",ch);ss=ch;
        }
        fclose(ff);
        
        qsort(a,l,sizeof(a[l+1]),cmp);
        int c[len]={0};
        for(int i=0;i<=l;i++)
        {
            int t=0;
            for(int j=0;j<a[i].length();j++)
                t+=s[a[i][j]-'a'];
            c[i]=t;
        }
        int u[26]={0};
        string ans[len];
        int p=0,kk[len]={0},max=0;
        for(int i=0;i<=l;i++)
            for(int j=i;j<=l+1;j++)
            {
                memset(u,0,sizeof(u));
                int l1;
                int yy=0;
                
                for(l1=0;l1<a[i].length();l1++)
                {
                    char x=a[i][l1];            
                    u[x-'a']++;
                    yy+=s[x-'a'];
                }
                for(l1=0;l1<a[j].length();l1++)
                {
                    char y=a[j][l1];
                    u[y-'a']++;
                    yy+=s[y-'a'];
                }
                bool bo=false;
                for(int k=0;k<26;k++)
                    if(u[k]>d[k]){bo=true;break;}
                if(!bo)
                {
                    ans[++p]=a[i];
                    if(a[j].length())ans[p]=a[i]+" "+a[j];
                    kk[p]=yy;if(yy>max)max=yy;
                }
            }
        cout<<max<<endl;
        for(int i=1;i<=p;i++)
            if(kk[i]==max)
                cout<<ans[i]<<endl;
    }
    
    int main () 
    {        
        test();        
        return 0;
    }

    test data:

    USACO Training
    Grader Results     
    14 users online
    BRA/1 CHN/3 GEO/1 IDN/1 IND/1 MKD/2 USA/5
    
    USER: cn tom [qq104801]
    TASK: lgame
    LANG: C++
    
    Compiling...
    Compile: OK
    
    Executing...
       Test 1: TEST OK [0.038 secs, 3848 KB]
       Test 2: TEST OK [0.016 secs, 3856 KB]
       Test 3: TEST OK [0.035 secs, 3856 KB]
       Test 4: TEST OK [0.046 secs, 3852 KB]
       Test 5: TEST OK [0.051 secs, 3852 KB]
       Test 6: TEST OK [0.046 secs, 3852 KB]
       Test 7: TEST OK [0.043 secs, 3856 KB]
       Test 8: TEST OK [0.038 secs, 3852 KB]
       Test 9: TEST OK [0.030 secs, 3852 KB]
       Test 10: TEST OK [0.046 secs, 3848 KB]
       Test 11: TEST OK [0.046 secs, 3852 KB]
       Test 12: TEST OK [0.049 secs, 3856 KB]
    
    All tests OK.
    
    YOUR PROGRAM ('lgame') WORKED FIRST TIME! That's fantastic -- and a rare thing. Please accept these special automated congratulations.
    
    Here are the test data inputs:
    
    ------- test 1 ----
    jicuzza
    ------- test 2 ----
    cuqak
    ------- test 3 ----
    pofax
    ------- test 4 ----
    rammoxy
    ------- test 5 ----
    culatu
    ------- test 6 ----
    gvutvac
    ------- test 7 ----
    bhruthr
    ------- test 8 ----
    wagje
    ------- test 9 ----
    thryst
    ------- test 10 ----
    fnupfig
    ------- test 11 ----
    bobdead
    ------- test 12 ----
    abcdefg
    
    Keep up the good work!
    Thanks for your submission!
    View Code
    /***********************************************

    看书看原版,原汁原味。

    不会英文?没关系,硬着头皮看下去慢慢熟练,才会有真正收获。

    没有原书,也要网上找PDF来看。

    网上的原版资料多了去了,下载东西也到原始下载点去看看。

    你会知其所以然,呵呵。

    ***********************************************/

  • 相关阅读:
    Hyper-V安装Centos7
    【DDD】使用领域驱动设计思想实现业务系统
    关于数据库‘状态’字段设计的思考与实践
    如何快速处理线上故障
    《企业应用架构模式》读后感
    java使用何种类型表示精确的小数?
    【项目经验】数据迁移总结
    springMVC引入Validation详解
    【DDD】领域驱动设计实践 —— 一些问题及想法
    【系统设计】“查询推荐好友”服务在不同架构风格下如何设计?
  • 原文地址:https://www.cnblogs.com/dpblue/p/3980474.html
Copyright © 2011-2022 走看看