Artifact Content
Not logged in

Artifact 5cb364fac0d3a48feec08e6019c65b2258d093d1


#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <cstring>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class FiveHundredEleven { public:
	string theWinner(vector <int> cards) 
	{
		return rec(cards, 511) ? "Fox Ciel" : "Toastman";
	}

	bool rec(const vector<int>& cards_, int goal)
	{
		if( goal == 0 )
			return true;

		bool inv = false;
		vector<int> cards;
		for(int i=0; i<cards_.size(); ++i)
			if( cards_[i]&goal )
				cards.push_back( cards_[i]&goal );
			else
				inv = !inv;

		for(int i=0; i<cards.size(); ++i)
		{
			const int c = cards[i];
			cards[i] = cards.back();
			cards.pop_back();

			if( !rec(cards, goal &~ c) )
				return true ^ inv;

			if( i < cards.size() ) {
				cards.push_back(cards[i]);
				cards[i] = c;
			}
		}
		return false ^ inv;
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const string& Expected, const string& Received) {
 bool ok = (Expected == Received);
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, FiveHundredEleven().theWinner(cards));}
int main(){

CASE(0)
	int cards_[] = {3, 5, 7, 9, 510};
	  vector <int> cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); 
	string _ = "Fox Ciel"; 
END
CASE(1)
	int cards_[] = {0, 0, 0, 0};
	  vector <int> cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); 
	string _ = "Toastman"; 
END
CASE(2)
	int cards_[] = {511};
	  vector <int> cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); 
	string _ = "Toastman"; 
END
CASE(3)
	int cards_[] = {5, 58, 192, 256};
	  vector <int> cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); 
	string _ = "Fox Ciel"; 
END
CASE(4)
	int cards_[] = {1};
	  vector <int> cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); 
	string _ = "Fox Ciel"; 
END
CASE(5)
	int cards_[] = {1,2,4,8,16,32,64,128,256};
	  vector <int> cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); 
	string _ = "Toastman"; 
END
/*
CASE(6)
	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};
	  vector <int> cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); 
	string _ = "???"; 
END
CASE(7)
	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};
	  vector <int> cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); 
	string _ = "Fox Ciel"; 
END
*/
CASE(8)
	int cards_[] = {461, 443, 177, 366, 499, 384, 125, 499, 372, 374, 39, 285, 203, 33, 429, 469, 458, 163, 154, 438, 508};
	  vector <int> cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); 
	string _ = "Toastman"; 
END
CASE(9)
	int cards_[] = {511, 0};
	  vector <int> cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); 
	string _ = "Fox Ciel"; 
END
CASE(10)
	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};
	  vector <int> cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); 
	string _ = "Fox Ciel"; 
END
}
// END CUT HERE