085e72a21b 2011-07-09 kinaba: #include <iostream> 085e72a21b 2011-07-09 kinaba: #include <sstream> 085e72a21b 2011-07-09 kinaba: #include <iomanip> 085e72a21b 2011-07-09 kinaba: #include <vector> 085e72a21b 2011-07-09 kinaba: #include <string> 085e72a21b 2011-07-09 kinaba: #include <map> 085e72a21b 2011-07-09 kinaba: #include <set> 085e72a21b 2011-07-09 kinaba: #include <algorithm> 085e72a21b 2011-07-09 kinaba: #include <numeric> 085e72a21b 2011-07-09 kinaba: #include <iterator> 085e72a21b 2011-07-09 kinaba: #include <functional> 085e72a21b 2011-07-09 kinaba: #include <complex> 085e72a21b 2011-07-09 kinaba: #include <queue> 085e72a21b 2011-07-09 kinaba: #include <stack> 085e72a21b 2011-07-09 kinaba: #include <cmath> 085e72a21b 2011-07-09 kinaba: #include <cassert> 085e72a21b 2011-07-09 kinaba: #include <cstring> 085e72a21b 2011-07-09 kinaba: using namespace std; 085e72a21b 2011-07-09 kinaba: typedef long long LL; 085e72a21b 2011-07-09 kinaba: typedef complex<double> CMP; 085e72a21b 2011-07-09 kinaba: 085e72a21b 2011-07-09 kinaba: class FiveHundredEleven { public: 085e72a21b 2011-07-09 kinaba: string theWinner(vector <int> cards) 085e72a21b 2011-07-09 kinaba: { 085e72a21b 2011-07-09 kinaba: return rec(cards, 511) ? "Fox Ciel" : "Toastman"; 085e72a21b 2011-07-09 kinaba: } 085e72a21b 2011-07-09 kinaba: 085e72a21b 2011-07-09 kinaba: bool rec(const vector<int>& cards_, int goal) 085e72a21b 2011-07-09 kinaba: { 085e72a21b 2011-07-09 kinaba: if( goal == 0 ) 085e72a21b 2011-07-09 kinaba: return true; 085e72a21b 2011-07-09 kinaba: 085e72a21b 2011-07-09 kinaba: bool inv = false; 085e72a21b 2011-07-09 kinaba: vector<int> cards; 085e72a21b 2011-07-09 kinaba: for(int i=0; i<cards_.size(); ++i) 085e72a21b 2011-07-09 kinaba: if( cards_[i]&goal ) 085e72a21b 2011-07-09 kinaba: cards.push_back( cards_[i]&goal ); 085e72a21b 2011-07-09 kinaba: else 085e72a21b 2011-07-09 kinaba: inv = !inv; 085e72a21b 2011-07-09 kinaba: 085e72a21b 2011-07-09 kinaba: for(int i=0; i<cards.size(); ++i) 085e72a21b 2011-07-09 kinaba: { 085e72a21b 2011-07-09 kinaba: const int c = cards[i]; 085e72a21b 2011-07-09 kinaba: cards[i] = cards.back(); 085e72a21b 2011-07-09 kinaba: cards.pop_back(); 085e72a21b 2011-07-09 kinaba: 085e72a21b 2011-07-09 kinaba: if( !rec(cards, goal &~ c) ) 085e72a21b 2011-07-09 kinaba: return true ^ inv; 085e72a21b 2011-07-09 kinaba: 085e72a21b 2011-07-09 kinaba: if( i < cards.size() ) { 085e72a21b 2011-07-09 kinaba: cards.push_back(cards[i]); 085e72a21b 2011-07-09 kinaba: cards[i] = c; 085e72a21b 2011-07-09 kinaba: } 085e72a21b 2011-07-09 kinaba: } 085e72a21b 2011-07-09 kinaba: return false ^ inv; 085e72a21b 2011-07-09 kinaba: } 085e72a21b 2011-07-09 kinaba: }; 085e72a21b 2011-07-09 kinaba: 085e72a21b 2011-07-09 kinaba: // BEGIN CUT HERE 085e72a21b 2011-07-09 kinaba: #include <ctime> 085e72a21b 2011-07-09 kinaba: double start_time; string timer() 085e72a21b 2011-07-09 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 085e72a21b 2011-07-09 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 085e72a21b 2011-07-09 kinaba: { os << "{ "; 085e72a21b 2011-07-09 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 085e72a21b 2011-07-09 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 085e72a21b 2011-07-09 kinaba: void verify_case(const string& Expected, const string& Received) { 085e72a21b 2011-07-09 kinaba: bool ok = (Expected == Received); 085e72a21b 2011-07-09 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 085e72a21b 2011-07-09 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 085e72a21b 2011-07-09 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 085e72a21b 2011-07-09 kinaba: #define END verify_case(_, FiveHundredEleven().theWinner(cards));} 085e72a21b 2011-07-09 kinaba: int main(){ 085e72a21b 2011-07-09 kinaba: 085e72a21b 2011-07-09 kinaba: CASE(0) 085e72a21b 2011-07-09 kinaba: int cards_[] = {3, 5, 7, 9, 510}; 085e72a21b 2011-07-09 kinaba: vector <int> cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); 085e72a21b 2011-07-09 kinaba: string _ = "Fox Ciel"; 085e72a21b 2011-07-09 kinaba: END 085e72a21b 2011-07-09 kinaba: CASE(1) 085e72a21b 2011-07-09 kinaba: int cards_[] = {0, 0, 0, 0}; 085e72a21b 2011-07-09 kinaba: vector <int> cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); 085e72a21b 2011-07-09 kinaba: string _ = "Toastman"; 085e72a21b 2011-07-09 kinaba: END 085e72a21b 2011-07-09 kinaba: CASE(2) 085e72a21b 2011-07-09 kinaba: int cards_[] = {511}; 085e72a21b 2011-07-09 kinaba: vector <int> cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); 085e72a21b 2011-07-09 kinaba: string _ = "Toastman"; 085e72a21b 2011-07-09 kinaba: END 085e72a21b 2011-07-09 kinaba: CASE(3) 085e72a21b 2011-07-09 kinaba: int cards_[] = {5, 58, 192, 256}; 085e72a21b 2011-07-09 kinaba: vector <int> cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); 085e72a21b 2011-07-09 kinaba: string _ = "Fox Ciel"; 085e72a21b 2011-07-09 kinaba: END 085e72a21b 2011-07-09 kinaba: CASE(4) 085e72a21b 2011-07-09 kinaba: int cards_[] = {1}; 085e72a21b 2011-07-09 kinaba: vector <int> cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); 085e72a21b 2011-07-09 kinaba: string _ = "Fox Ciel"; 085e72a21b 2011-07-09 kinaba: END 085e72a21b 2011-07-09 kinaba: CASE(5) 085e72a21b 2011-07-09 kinaba: int cards_[] = {1,2,4,8,16,32,64,128,256}; 085e72a21b 2011-07-09 kinaba: vector <int> cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); 085e72a21b 2011-07-09 kinaba: string _ = "Toastman"; 085e72a21b 2011-07-09 kinaba: END 085e72a21b 2011-07-09 kinaba: /* 085e72a21b 2011-07-09 kinaba: CASE(6) 085e72a21b 2011-07-09 kinaba: int cards_[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,64,128,256}; 085e72a21b 2011-07-09 kinaba: vector <int> cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); 085e72a21b 2011-07-09 kinaba: string _ = "???"; 085e72a21b 2011-07-09 kinaba: END 085e72a21b 2011-07-09 kinaba: CASE(7) 085e72a21b 2011-07-09 kinaba: int cards_[] = {2, 0, 0, 0, 32, 0, 0, 0, 0, 64, 0, 32, 0, 0, 128, 8, 128, 0, 4, 0, 0, 1, 0, 0, 64, 0, 0, 128, 0, 16, 0, 8, 0, 18, 260, 257, 2, 0, 64, 0, 0, 0, 40, 0, 0, 1, 0, 0, 1, 0}; 085e72a21b 2011-07-09 kinaba: vector <int> cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); 085e72a21b 2011-07-09 kinaba: string _ = "Fox Ciel"; 085e72a21b 2011-07-09 kinaba: END 085e72a21b 2011-07-09 kinaba: */ 085e72a21b 2011-07-09 kinaba: CASE(8) 085e72a21b 2011-07-09 kinaba: int cards_[] = {461, 443, 177, 366, 499, 384, 125, 499, 372, 374, 39, 285, 203, 33, 429, 469, 458, 163, 154, 438, 508}; 085e72a21b 2011-07-09 kinaba: vector <int> cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); 085e72a21b 2011-07-09 kinaba: string _ = "Toastman"; 085e72a21b 2011-07-09 kinaba: END 085e72a21b 2011-07-09 kinaba: CASE(9) 085e72a21b 2011-07-09 kinaba: int cards_[] = {511, 0}; 085e72a21b 2011-07-09 kinaba: vector <int> cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); 085e72a21b 2011-07-09 kinaba: string _ = "Fox Ciel"; 085e72a21b 2011-07-09 kinaba: END 085e72a21b 2011-07-09 kinaba: CASE(10) 085e72a21b 2011-07-09 kinaba: int cards_[] = {2, 0, 0, 0, 32, 0, 0, 0, 0, 64, 0, 32, 0, 0, 128, 8, 128, 0, 4, 0, 0, 1, 0, 0, 64, 0, 0, 128, 0, 16, 0, 8, 0, 18, 260, 257, 2, 0, 64, 0, 0, 0, 40, 0, 0, 1, 0, 0, 1, 0}; 085e72a21b 2011-07-09 kinaba: vector <int> cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); 085e72a21b 2011-07-09 kinaba: string _ = "Fox Ciel"; 085e72a21b 2011-07-09 kinaba: END 085e72a21b 2011-07-09 kinaba: } 085e72a21b 2011-07-09 kinaba: // END CUT HERE