4fd800b3a8 2011-02-23 kinaba: #include <iostream> 4fd800b3a8 2011-02-23 kinaba: #include <sstream> 4fd800b3a8 2011-02-23 kinaba: #include <iomanip> 4fd800b3a8 2011-02-23 kinaba: #include <vector> 4fd800b3a8 2011-02-23 kinaba: #include <string> 4fd800b3a8 2011-02-23 kinaba: #include <map> 4fd800b3a8 2011-02-23 kinaba: #include <set> 4fd800b3a8 2011-02-23 kinaba: #include <algorithm> 4fd800b3a8 2011-02-23 kinaba: #include <numeric> 4fd800b3a8 2011-02-23 kinaba: #include <iterator> 4fd800b3a8 2011-02-23 kinaba: #include <complex> 4fd800b3a8 2011-02-23 kinaba: #include <queue> 4fd800b3a8 2011-02-23 kinaba: #include <stack> 4fd800b3a8 2011-02-23 kinaba: #include <cmath> 4fd800b3a8 2011-02-23 kinaba: using namespace std; 4fd800b3a8 2011-02-23 kinaba: typedef long long LL; 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: class VolleyballTournament 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: public: 4fd800b3a8 2011-02-23 kinaba: string reconstructResults(int wonMatches, int lostMatches, int wonSets, int lostSets) 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: //0-3, 1-3, 2-3, 3-0, 3-1, 3-2 4fd800b3a8 2011-02-23 kinaba: //Z0 Z1 Z2 W0 W1 W2 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: //Z0+ Z1 + Z2 == lostMatches 4fd800b3a8 2011-02-23 kinaba: //Z0*0 + Z1*1 + Z2*2 + 3*wonMatches == wonSets 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: //W0+W1+W2 == wonMatches 4fd800b3a8 2011-02-23 kinaba: //W0*0+W1*1+W2*2+3*lostMatches == lostSets 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: int a[6] = {-1}; 4fd800b3a8 2011-02-23 kinaba: for(int Z1=0; Z1<=lostMatches; ++Z1) 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: int Z2 = (wonSets - 3*wonMatches - Z1) / 2; 4fd800b3a8 2011-02-23 kinaba: int Z0 = lostMatches - Z1 - Z2; 4fd800b3a8 2011-02-23 kinaba: if( Z0<0 || Z2<0 || lostMatches<Z0 || lostMatches<Z2 ) continue; 4fd800b3a8 2011-02-23 kinaba: if( Z1+Z2*2+3*wonMatches != wonSets ) continue; 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: for(int W1=0; W1<=wonMatches; ++W1) 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: int W2 = (lostSets - 3*lostMatches - W1) / 2; 4fd800b3a8 2011-02-23 kinaba: int W0 = wonMatches - W1 - W2; 4fd800b3a8 2011-02-23 kinaba: if( W0<0 || W2<0 || wonMatches<W0 || wonMatches<W2 ) continue; 4fd800b3a8 2011-02-23 kinaba: if( W1+W2*2+3*lostMatches != lostSets ) continue; 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: if( a[0]>=0 ) 4fd800b3a8 2011-02-23 kinaba: return "AMBIGUITY"; 4fd800b3a8 2011-02-23 kinaba: else 4fd800b3a8 2011-02-23 kinaba: a[0]=Z0, a[1]=Z1, a[2]=Z2, a[3]=W0, a[4]=W1, a[5]=W2; 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: const char* s[6] = {"0-3", "1-3", "2-3", "3-0", "3-1", "3-2"}; 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: string ans; 4fd800b3a8 2011-02-23 kinaba: for(int i=0; i<6; ++i) 4fd800b3a8 2011-02-23 kinaba: for(int j=0; j<a[i]; ++j) 4fd800b3a8 2011-02-23 kinaba: ans += s[i], ans += ","; 4fd800b3a8 2011-02-23 kinaba: ans.resize(ans.size()-1); 4fd800b3a8 2011-02-23 kinaba: return ans; 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: // BEGIN CUT HERE 4fd800b3a8 2011-02-23 kinaba: public: 4fd800b3a8 2011-02-23 kinaba: 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(); } 4fd800b3a8 2011-02-23 kinaba: private: 4fd800b3a8 2011-02-23 kinaba: 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(); } 4fd800b3a8 2011-02-23 kinaba: 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; } } 4fd800b3a8 2011-02-23 kinaba: void test_case_0() { int Arg0 = 3; int Arg1 = 3; int Arg2 = 9; int Arg3 = 9; string Arg4 = "0-3,0-3,0-3,3-0,3-0,3-0"; verify_case(0, Arg4, reconstructResults(Arg0, Arg1, Arg2, Arg3)); } 4fd800b3a8 2011-02-23 kinaba: void test_case_1() { int Arg0 = 0; int Arg1 = 3; int Arg2 = 6; int Arg3 = 9; string Arg4 = "2-3,2-3,2-3"; verify_case(1, Arg4, reconstructResults(Arg0, Arg1, Arg2, Arg3)); } 4fd800b3a8 2011-02-23 kinaba: void test_case_2() { int Arg0 = 3; int Arg1 = 0; int Arg2 = 9; int Arg3 = 3; string Arg4 = "AMBIGUITY"; verify_case(2, Arg4, reconstructResults(Arg0, Arg1, Arg2, Arg3)); } 4fd800b3a8 2011-02-23 kinaba: void test_case_3() { int Arg0 = 1; int Arg1 = 1; int Arg2 = 4; int Arg3 = 4; string Arg4 = "1-3,3-1"; verify_case(3, Arg4, reconstructResults(Arg0, Arg1, Arg2, Arg3)); } 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: // END CUT HERE 4fd800b3a8 2011-02-23 kinaba: }; 4fd800b3a8 2011-02-23 kinaba: // BEGIN CUT HERE 4fd800b3a8 2011-02-23 kinaba: int main() { 4fd800b3a8 2011-02-23 kinaba: VolleyballTournament().run_test(-1); 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: // END CUT HERE