TopCoder SRMに初挑戦してみました。
解けた問題はDvi2の250問題です。
Easy問題って言うのかな?
結果は177点くらいとって、レーティング845の灰色です。
次は緑に昇格できるよう、がんばります。
とりあえずソースコード
// BEGIN CUT HERE // END CUT HERE #line 5 "DengklekTryingToSleep.cpp" #include <string> #include <vector> #include <sstream> #include <iostream> using namespace std; class DengklekTryingToSleep { public: int minDucks(vector <int> ducks) { //sortする sort(ducks.begin(), ducks.end()); int min = ducks[0]; int max = ducks[ducks.size() - 1]; int count_row = 0; int count = 0; for (int i=min; i <= max; i++) { if (i == ducks[count_row]) { count_row++; }else { count++; } } return count; } // BEGIN CUT HERE public: void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0(); if ((Case == -1) || (Case == 1)) test_case_1(); if ((Case == -1) || (Case == 2)) test_case_2(); if ((Case == -1) || (Case == 3)) test_case_3(); if ((Case == -1) || (Case == 4)) test_case_4(); } private: template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); } void verify_case(int Case, const int &Expected, const int &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } } void test_case_0() { int Arr0[] = {5, 3, 2}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 1; verify_case(0, Arg1, minDucks(Arg0)); } void test_case_1() { int Arr0[] = {58}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 0; verify_case(1, Arg1, minDucks(Arg0)); } void test_case_2() { int Arr0[] = {9, 3, 6, 4}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 3; verify_case(2, Arg1, minDucks(Arg0)); } void test_case_3() { int Arr0[] = {7, 4, 77, 47, 74, 44}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 68; verify_case(3, Arg1, minDucks(Arg0)); } void test_case_4() { int Arr0[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 0; verify_case(4, Arg1, minDucks(Arg0)); } // END CUT HERE }; // BEGIN CUT HERE int main() { DengklekTryingToSleep ___test; ___test.run_test(-1); } // END CUT HERE