感覺USACO 沒有大家說的那麽容易啊(兄貴進來,叫你兒子給小姑娘調試一下代碼,鼓勵後進)
女兒在參加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