感觉USACO 没有大家说的那么容易啊

来源: paterman 2023-02-17 19:32:53 [] [旧帖] [给我悄悄话] 本文已被阅读: 次 (16843 bytes)
回答: 我觉得没人可以帮助这位paterman2023-02-06 14:02:03

 

 

 

感觉USACO 没有大家说的那么容易啊(兄贵进来,叫你儿子给小姑娘调试一下代码,鼓励后进)

 
来源:  于 2023-02-17 15:33:57 [] [旧帖] [给我悄悄话] 本文已被阅读: 1534 次 (12060 bytes)
本文内容已被 [ 里鱼 ] 在 2023-02-17 16:03:53 编辑过。如有问题,请报告版主或论坛管理删除.

女儿在参加USACO 的银牌培训。她铜牌已经过了。铜牌培训时,感觉非常容易,所以对她参加银牌培训,基本全放羊, 完全不管。

今天她遇到问题了。一个作业她怎么调程序也得不到答案。上楼问我。我看了一下题目,吃了一惊。题目不是很难,但是涉及到很多东西,比如数学的排列组合问题。真的想不到,学到银牌这个阶段,涉及到东西这么多,这里边有编程语言代码本身的问题(她用的是C++),也有英语的阅读理解,数学等等一系列问题。

翻紫檀以前的贴子,给人的感觉就是,“USACO ,或者编程语言根本不需要学,只要需要的时候再学也完全来得及"云云。。。

 

从这个例子看来,看来要么是女儿太蠢!要么就是人云亦云,以讹传讹。

 

以下是她写的代码,这里大拿多,给看看到底拿出毛病了。
#include <iostream>
#include <string>
#include <algorithm>
//22, 7
using namespace std;

int main(){
    int n, k, x = 0; cin >> n >> k;
    string la, list[n];
    getline(cin, la);
    for (int i = 0; i < n; i++){
        getline(cin, la);
        int o = la.length();
        la = la.substr(22, o-29);
        if (i == 0){
            int sum = 0;
            for (int j = 0; j < la.length(); j++){
                if (la[j] == ' '){
                    sum++;
                }
            }
            x = sum + 1;
        }
        list[i] = la + " ";
        //cout << la + " "<< endl;
    }
    //cout << x << endl;
    sort(list, list+n);
    string max[x];
    for (int i = 0; i < n; i++){
        int last = 0;
        int cur = 0;
        for (int j = 0; j < list[i].length(); j++){
            if (list[i][j] == ' '){
                max[cur] += list[i].substr(last, j-last) + " ";
                //cout << list[i].substr(last, j-last) << endl;
                //break;
                last = j+1;
                cur++;
            }
        }
    }
    int num[x];
    int cur;
    int last;
    ///////////////////////////
    
    string store[n][n];
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            store[i][j] = "";
        }
    }
    
    ///////////////////////////
    for (int i = 0; i < x; i++){
        num[i] = 0;
        last = 0;
        cur = 0;
        string test[n];
        for (int a = 0; a < n; a++){
            test[a] = "";
        }
        //cout << max[i] << endl;
        for (int j = 0; j < max[i].length(); j++){
            if (max[i][j] == ' '){
                test[cur] = max[i].substr(last, j-last);
                //cout << test[cur] << " ";
                cur++;
                last = j+1;
            }
        }
        //cout << endl;
        int sum = 0;
        sort(test, test+cur);
        for (int j = 1; j < cur; j++){
            //if ()
            if (test[j] != test[j-1]){
                sum++;
            }
            if (test[j] == test[j-1]){
                //cout << test[j] << endl;
                test[j-1] = "";
            }
        }
        //cout << sum + 1;
        num[i] = sum + 1;
        for (int b = 0; b < cur; b++){
            if (test[b] != ""){
                //cout << test[b] << " ";
                store[b][i] = test[b];
            }
        }
        //cout << endl;
        //cout << num[i] << endl;
    }
    
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            cout << store[i][j] << "x";
        }
        cout << endl;
    }
    //cout << store[1][0];
    
    for (int i = 0; i < x; i++){
        //cout << num[i] << " ";
    }
    
    
    
    return 0;
}

 

 

 

这是assignment .

Acorn Collection

Harry loves to collect acorns of all shapes, sizes, colors, and textures. He has collected almost all the types of acorn that can be found in the woods. The only ones he doesn’t have are listed on N lines (1 <= N <= 100). For example:

Squirrel Harry has no small green smooth acorn.
Squirrel Harry has no big brown smooth acorn.
Squirrel Harry has no big red shiny acorn.

Each item in the list describes a missing acorn in terms of a short list of adjectives, and each item contains the same number of adjectives (3, in this case). The number of adjectives per line will be in the range 2..30.

Harry has an acorn for every other possible adjective combination not on his list. The acorns can only be small or big; brown, red, or green; smooth or shiny. This amounts to 2 x 3 x 2 = 12 different combinations. Harry thinks there are at most 1,000,000,000 acorns in his collection. 

If Harry lists the acorns that he does have in alphabetical order, what is the Kth acorn in this list?

Partial credit opportunities: In the 10 test cases for this problem, cases 1..4 involve at most two adjectives per line in Harry's list. In cases 1..6, each adjective slot will have exactly two possible settings (in all other cases, each adjective will have between 1 and N possible settings).

INPUT FORMAT

Line 1: two integers: N and K

Lines 2 .. 1+N: Each line is a sentence like “Squirrel Harry has no small green smooth acorn.” Each adjective in the sentence will be a string of at most 10 lowercase letters. The end of the sentence will always be “acorn.” (That is including the period at the end of the sentence.)

OUTPUT FORMAT

Line 1: A string describing the Kth acorn that Harry has. 

SAMPLE INPUT

4 3
Squirrel Harry has no small green smooth acorn.
Squirrel Harry has no big brown smooth acorn.
Squirrel Harry has no big red shiny acorn.
Squirrel Harry has no small brown shiny acorn.

SAMPLE OUTPUT

big green smooth

Harry has acorns matching the following descriptions, listed in alphabetical order:

big brown shiny
big green shiny
big green smooth
big red smooth
small brown smooth
small green shiny
small red shiny
small red smooth

 

 

所有跟帖: 

推荐这个。 我是明白了才看到这个。早看到少走弯路 -paterman- 给 paterman 发送悄悄话 (5182 bytes) () 02/17/2023 postreply 19:43:46

请您先登陆,再发跟帖!

发现Adblock插件

如要继续浏览
请支持本站 请务必在本站关闭/移除任何Adblock

关闭Adblock后 请点击

请参考如何关闭Adblock/Adblock plus

安装Adblock plus用户请点击浏览器图标
选择“Disable on www.wenxuecity.com”

安装Adblock用户请点击图标
选择“don't run on pages on this domain”