|
| 1 | +#include <iostream> |
| 2 | +#include <cstdio> |
| 3 | +#include <sstream> |
| 4 | +#include <cstring> |
| 5 | +#include <vector> |
| 6 | +#include <list> |
| 7 | +#include <algorithm> |
| 8 | +#include <set> |
| 9 | +#include <map> |
| 10 | +using namespace std; |
| 11 | +int sol[10][100]; |
| 12 | +vector<int> m; |
| 13 | +int col[10]; |
| 14 | + |
| 15 | +class WeirdRooks { |
| 16 | + public: |
| 17 | + void fun(int r, int nr, int ns){ |
| 18 | + |
| 19 | + if(r < 0){ |
| 20 | + sol[nr][ns] = 1; |
| 21 | + return; |
| 22 | + } |
| 23 | + |
| 24 | + int ts = 0; |
| 25 | + for(int j = m[r]-1; j >= 0; j--){ |
| 26 | + if(!col[j]){ |
| 27 | + col[j] = 1; |
| 28 | + fun(r-1, nr+1, ns+ts); |
| 29 | + col[j] = 0; |
| 30 | + ts++; |
| 31 | + } |
| 32 | + } |
| 33 | + fun(r-1, nr, ns+ts); |
| 34 | + } |
| 35 | + |
| 36 | + string describe(vector <int> cols) |
| 37 | + { |
| 38 | + memset(sol, 0, 1000*sizeof(int)); |
| 39 | + m = cols; |
| 40 | + string ret = ""; |
| 41 | + fun(cols.size()-1, 0, 0); |
| 42 | + for(int i = 0; i < 10; i++){ |
| 43 | + for(int j = 0; j < 100; j++) |
| 44 | + if(sol[i][j]){ |
| 45 | + char s[10]; |
| 46 | + sprintf(s, "%d,%d", i, j); |
| 47 | + if(ret.size()) ret += ' '; |
| 48 | + ret += s; |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + return ret; |
| 53 | + } |
| 54 | + |
| 55 | +// BEGIN CUT HERE |
| 56 | + public: |
| 57 | + 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(); } |
| 58 | + private: |
| 59 | + 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(); } |
| 60 | + void verify_case(int Case, const string &Expected, const string &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } } |
| 61 | + void test_case_0() { int Arr0[] = {3,3,3}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); string Arg1 = "0,9 1,4 1,5 1,6 1,7 1,8 2,1 2,2 2,3 2,4 2,5 2,6 3,0 3,1 3,2 3,3"; verify_case(0, Arg1, describe(Arg0)); } |
| 62 | + void test_case_1() { int Arr0[] = {1,2,3}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); string Arg1 = "0,6 1,3 1,4 1,5 2,1 2,2 2,3 3,0"; verify_case(1, Arg1, describe(Arg0)); } |
| 63 | + void test_case_2() { int Arr0[] = {1}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); string Arg1 = "0,1 1,0"; verify_case(2, Arg1, describe(Arg0)); } |
| 64 | + void test_case_3() { int Arr0[] = {2,9}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); string Arg1 = "0,11 1,2 1,3 1,4 1,5 1,6 1,7 1,8 1,9 1,10 2,0 2,1 2,2 2,3 2,4 2,5 2,6 2,7 2,8"; verify_case(3, Arg1, describe(Arg0)); } |
| 65 | + |
| 66 | +// END CUT HERE |
| 67 | + |
| 68 | +}; |
| 69 | + |
| 70 | +// BEGIN CUT HERE |
| 71 | + int main() |
| 72 | + { |
| 73 | + WeirdRooks ___test; |
| 74 | + ___test.run_test(-1); |
| 75 | + } |
| 76 | +// END CUT HERE |
0 commit comments