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