ADDED SRM/511-U/1A-U.cpp Index: SRM/511-U/1A-U.cpp ================================================================== --- SRM/511-U/1A-U.cpp +++ SRM/511-U/1A-U.cpp @@ -0,0 +1,112 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef long long LL; +typedef complex CMP; + +class Zoo { public: + long long theCount(vector answers) + { + map nc; + for(int i=0; i +double start_time; string timer() + { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } +template ostream& operator<<(ostream& os, const vector& v) + { os << "{ "; + for(typename vector::const_iterator it=v.begin(); it!=v.end(); ++it) + os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } +void verify_case(const long long& Expected, const long long& 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(_, Zoo().theCount(answers));} +int main(){ + +CASE(0) + int answers_[] = {0, 1, 2, 3, 4}; + vector answers(answers_, answers_+sizeof(answers_)/sizeof(*answers_)); + long long _ = 2LL; +END +CASE(1) + int answers_[] = {5, 8}; + vector answers(answers_, answers_+sizeof(answers_)/sizeof(*answers_)); + long long _ = 0LL; +END +CASE(2) + int answers_[] = {0, 0, 0, 0, 0, 0}; + vector answers(answers_, answers_+sizeof(answers_)/sizeof(*answers_)); + long long _ = 0LL; +END +CASE(3) + int answers_[] = {1, 0, 2, 0, 1}; + vector answers(answers_, answers_+sizeof(answers_)/sizeof(*answers_)); + long long _ = 8LL; +END +CASE(4) + int answers_[] = {1, 0, 1}; + vector answers(answers_, answers_+sizeof(answers_)/sizeof(*answers_)); + long long _ = 0LL; +END +/* +CASE(5) + int answers_[] = ; + vector answers(answers_, answers_+sizeof(answers_)/sizeof(*answers_)); + long long _ = LL; +END +CASE(6) + int answers_[] = ; + vector answers(answers_, answers_+sizeof(answers_)/sizeof(*answers_)); + long long _ = LL; +END +*/ +} +// END CUT HERE ADDED SRM/511-U/1B-U.cpp Index: SRM/511-U/1B-U.cpp ================================================================== --- SRM/511-U/1B-U.cpp +++ SRM/511-U/1B-U.cpp @@ -0,0 +1,133 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef long long LL; +typedef complex CMP; + +class FiveHundredEleven { public: + string theWinner(vector cards) + { + return rec(cards, 511) ? "Fox Ciel" : "Toastman"; + } + + bool rec(const vector& cards_, int goal) + { + if( goal == 0 ) + return true; + + bool inv = false; + vector cards; + for(int i=0; i +double start_time; string timer() + { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } +template ostream& operator<<(ostream& os, const vector& v) + { os << "{ "; + for(typename vector::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 cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); + string _ = "Fox Ciel"; +END +CASE(1) + int cards_[] = {0, 0, 0, 0}; + vector cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); + string _ = "Toastman"; +END +CASE(2) + int cards_[] = {511}; + vector cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); + string _ = "Toastman"; +END +CASE(3) + int cards_[] = {5, 58, 192, 256}; + vector cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); + string _ = "Fox Ciel"; +END +CASE(4) + int cards_[] = {1}; + vector 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 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 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 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 cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); + string _ = "Toastman"; +END +CASE(9) + int cards_[] = {511, 0}; + vector 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 cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); + string _ = "Fox Ciel"; +END +} +// END CUT HERE ADDED lib/typical/BigIntegerUseCase.java Index: lib/typical/BigIntegerUseCase.java ================================================================== --- lib/typical/BigIntegerUseCase.java +++ lib/typical/BigIntegerUseCase.java @@ -0,0 +1,39 @@ +import java.math.*; +import java.util.*; + +public class ZenoDivision { + static BigInteger ZERO = BigInteger.ZERO; + static BigInteger ONE = BigInteger.ONE; + static BigInteger TWO = BigInteger.valueOf(2); + static BigInteger TEN = BigInteger.TEN; + + public String cycle(String a_, String b_) + { + BigInteger a = new BigInteger(a_); + BigInteger b = new BigInteger(b_); + + if( b.remainder(TWO).equals(ZERO) ) + return "impossible"; + if( a.equals(ZERO) && b.equals(ONE) ) + return "-"; + if( a.equals(ONE) && b.equals(ONE) ) + return "*"; + + int x = 1; + while( !TWO.modPow(BigInteger.valueOf(x),b).equals(ONE) ) { + x++; + if( x >= 61 ) + return "impossible"; + } + + BigInteger z = TWO.pow(x).subtract(ONE).divide(b); + String str = a.multiply(z).toString(2); + while( str.length() < x ) + str = "0" + str; + + String answer = ""; + for(int i=0; i