码迷,mamicode.com
首页 > 其他好文 > 详细

usaco-4.3-lgame-passed

时间:2014-09-19 01:08:14      阅读:308      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   ar   for   div   

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

/*
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:

bubuko.com,布布扣
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

 

usaco-4.3-lgame-passed

标签:style   blog   http   color   io   os   ar   for   div   

原文地址:http://www.cnblogs.com/dpblue/p/3980474.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!