8166493378 2012-05-12 kinaba: #include <iostream> 8166493378 2012-05-12 kinaba: #include <sstream> 8166493378 2012-05-12 kinaba: #include <iomanip> 8166493378 2012-05-12 kinaba: #include <vector> 8166493378 2012-05-12 kinaba: #include <string> 8166493378 2012-05-12 kinaba: #include <map> 8166493378 2012-05-12 kinaba: #include <set> 8166493378 2012-05-12 kinaba: #include <algorithm> 8166493378 2012-05-12 kinaba: #include <numeric> 8166493378 2012-05-12 kinaba: #include <iterator> 8166493378 2012-05-12 kinaba: #include <functional> 8166493378 2012-05-12 kinaba: #include <complex> 8166493378 2012-05-12 kinaba: #include <queue> 8166493378 2012-05-12 kinaba: #include <stack> 8166493378 2012-05-12 kinaba: #include <cmath> 8166493378 2012-05-12 kinaba: #include <cassert> 8166493378 2012-05-12 kinaba: #include <cstring> 8166493378 2012-05-12 kinaba: #ifdef __GNUC__ 8166493378 2012-05-12 kinaba: #include <ext/hash_map> 8166493378 2012-05-12 kinaba: #define unordered_map __gnu_cxx::hash_map 8166493378 2012-05-12 kinaba: #else 8166493378 2012-05-12 kinaba: #include <unordered_map> 8166493378 2012-05-12 kinaba: #endif 8166493378 2012-05-12 kinaba: using namespace std; 8166493378 2012-05-12 kinaba: typedef long long LL; 8166493378 2012-05-12 kinaba: typedef complex<double> CMP; 8166493378 2012-05-12 kinaba: 8166493378 2012-05-12 kinaba: class EllysJuice { public: 8166493378 2012-05-12 kinaba: vector <string> getWinners(vector <string> players) 8166493378 2012-05-12 kinaba: { 8166493378 2012-05-12 kinaba: set<string> winners; 8166493378 2012-05-12 kinaba: 8166493378 2012-05-12 kinaba: sort(players.begin(), players.end()); 8166493378 2012-05-12 kinaba: do 8166493378 2012-05-12 kinaba: winners.insert( play(players) ); 8166493378 2012-05-12 kinaba: while( next_permutation(players.begin(), players.end()) ); 8166493378 2012-05-12 kinaba: 8166493378 2012-05-12 kinaba: winners.erase(""); 8166493378 2012-05-12 kinaba: return vector<string>(winners.begin(), winners.end()); 8166493378 2012-05-12 kinaba: } 8166493378 2012-05-12 kinaba: 8166493378 2012-05-12 kinaba: string play(const vector<string>& p) 8166493378 2012-05-12 kinaba: { 8166493378 2012-05-12 kinaba: int juice[2] = {65536, 65536}; 8166493378 2012-05-12 kinaba: map<string, int> total; 8166493378 2012-05-12 kinaba: for(int i=0; i<p.size(); ++i) 8166493378 2012-05-12 kinaba: total[p[i]] += (juice[i%2]/=2); 8166493378 2012-05-12 kinaba: 8166493378 2012-05-12 kinaba: string best_name; 8166493378 2012-05-12 kinaba: int best = 0; 8166493378 2012-05-12 kinaba: bool tie = false; 8166493378 2012-05-12 kinaba: for(map<string, int>::iterator it=total.begin(); it!=total.end(); ++it) 8166493378 2012-05-12 kinaba: if( it->second > best ) { 8166493378 2012-05-12 kinaba: best_name = it->first; 8166493378 2012-05-12 kinaba: best = it->second; 8166493378 2012-05-12 kinaba: tie = false; 8166493378 2012-05-12 kinaba: } 8166493378 2012-05-12 kinaba: else if( it->second == best ) 8166493378 2012-05-12 kinaba: tie = true; 8166493378 2012-05-12 kinaba: return tie ? "" : best_name; 8166493378 2012-05-12 kinaba: } 8166493378 2012-05-12 kinaba: }; 8166493378 2012-05-12 kinaba: 8166493378 2012-05-12 kinaba: // BEGIN CUT HERE 8166493378 2012-05-12 kinaba: #include <ctime> 8166493378 2012-05-12 kinaba: double start_time; string timer() 8166493378 2012-05-12 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 8166493378 2012-05-12 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 8166493378 2012-05-12 kinaba: { os << "{ "; 8166493378 2012-05-12 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 8166493378 2012-05-12 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 8166493378 2012-05-12 kinaba: void verify_case(const vector <string>& Expected, const vector <string>& Received) { 8166493378 2012-05-12 kinaba: bool ok = (Expected == Received); 8166493378 2012-05-12 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 8166493378 2012-05-12 kinaba: cerr << "\to: " << Expected << endl << "\tx: " << Received << endl; } } 8166493378 2012-05-12 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 8166493378 2012-05-12 kinaba: #define END verify_case(_, EllysJuice().getWinners(players));} 8166493378 2012-05-12 kinaba: int main(){ 8166493378 2012-05-12 kinaba: 8166493378 2012-05-12 kinaba: CASE(0) 8166493378 2012-05-12 kinaba: string players_[] = { "elly", "kriss", "stancho", "elly", "stancho" }; 8166493378 2012-05-12 kinaba: vector <string> players(players_, players_+sizeof(players_)/sizeof(*players_)); 8166493378 2012-05-12 kinaba: string __[] = {"elly", "stancho" }; 8166493378 2012-05-12 kinaba: vector <string> _(__, __+sizeof(__)/sizeof(*__)); 8166493378 2012-05-12 kinaba: END 8166493378 2012-05-12 kinaba: CASE(1) 8166493378 2012-05-12 kinaba: string players_[] = {"torb", "elly", "stancho", "kriss"}; 8166493378 2012-05-12 kinaba: vector <string> players(players_, players_+sizeof(players_)/sizeof(*players_)); 8166493378 2012-05-12 kinaba: vector <string> _; 8166493378 2012-05-12 kinaba: END 8166493378 2012-05-12 kinaba: CASE(2) 8166493378 2012-05-12 kinaba: string players_[] = {"elly", "elly", "elly", "elly", "elly"}; 8166493378 2012-05-12 kinaba: vector <string> players(players_, players_+sizeof(players_)/sizeof(*players_)); 8166493378 2012-05-12 kinaba: string __[] = {"elly" }; 8166493378 2012-05-12 kinaba: vector <string> _(__, __+sizeof(__)/sizeof(*__)); 8166493378 2012-05-12 kinaba: END 8166493378 2012-05-12 kinaba: CASE(3) 8166493378 2012-05-12 kinaba: string players_[] = { "ariadne", "elly", "ariadne", "stancho", "stancho", "kriss", "stancho", "elly" }; 8166493378 2012-05-12 kinaba: vector <string> players(players_, players_+sizeof(players_)/sizeof(*players_)); 8166493378 2012-05-12 kinaba: string __[] = {"ariadne", "elly", "stancho" }; 8166493378 2012-05-12 kinaba: vector <string> _(__, __+sizeof(__)/sizeof(*__)); 8166493378 2012-05-12 kinaba: END 8166493378 2012-05-12 kinaba: CASE(4) 8166493378 2012-05-12 kinaba: string players_[] = {"b","b","a","a"}; 8166493378 2012-05-12 kinaba: vector <string> players(players_, players_+sizeof(players_)/sizeof(*players_)); 8166493378 2012-05-12 kinaba: string __[] = {"a","b"}; 8166493378 2012-05-12 kinaba: vector <string> _(__, __+sizeof(__)/sizeof(*__)); 8166493378 2012-05-12 kinaba: END 8166493378 2012-05-12 kinaba: /* 8166493378 2012-05-12 kinaba: CASE(5) 8166493378 2012-05-12 kinaba: string players_[] = ; 8166493378 2012-05-12 kinaba: vector <string> players(players_, players_+sizeof(players_)/sizeof(*players_)); 8166493378 2012-05-12 kinaba: string __[] = ; 8166493378 2012-05-12 kinaba: vector <string> _(__, __+sizeof(__)/sizeof(*__)); 8166493378 2012-05-12 kinaba: END 8166493378 2012-05-12 kinaba: */ 8166493378 2012-05-12 kinaba: } 8166493378 2012-05-12 kinaba: // END CUT HERE