f6f3e6962a 2011-04-09 kinaba: #include <iostream> f6f3e6962a 2011-04-09 kinaba: #include <sstream> f6f3e6962a 2011-04-09 kinaba: #include <iomanip> f6f3e6962a 2011-04-09 kinaba: #include <vector> f6f3e6962a 2011-04-09 kinaba: #include <string> f6f3e6962a 2011-04-09 kinaba: #include <map> f6f3e6962a 2011-04-09 kinaba: #include <set> f6f3e6962a 2011-04-09 kinaba: #include <algorithm> f6f3e6962a 2011-04-09 kinaba: #include <numeric> f6f3e6962a 2011-04-09 kinaba: #include <iterator> f6f3e6962a 2011-04-09 kinaba: #include <functional> f6f3e6962a 2011-04-09 kinaba: #include <complex> f6f3e6962a 2011-04-09 kinaba: #include <queue> f6f3e6962a 2011-04-09 kinaba: #include <stack> f6f3e6962a 2011-04-09 kinaba: #include <cmath> f6f3e6962a 2011-04-09 kinaba: #include <cassert> f6f3e6962a 2011-04-09 kinaba: #include <cstring> f6f3e6962a 2011-04-09 kinaba: using namespace std; f6f3e6962a 2011-04-09 kinaba: typedef long long LL; f6f3e6962a 2011-04-09 kinaba: typedef complex<double> CMP; f6f3e6962a 2011-04-09 kinaba: f6f3e6962a 2011-04-09 kinaba: class FoxPlayingGame { public: f6f3e6962a 2011-04-09 kinaba: double theMax(int nA, int nB, int paramA, int paramB) f6f3e6962a 2011-04-09 kinaba: { f6f3e6962a 2011-04-09 kinaba: double scoreA = paramA / 1000.0; f6f3e6962a 2011-04-09 kinaba: double scoreB = paramB / 1000.0; f6f3e6962a 2011-04-09 kinaba: f6f3e6962a 2011-04-09 kinaba: double cur=scoreA*nA, best=cur; f6f3e6962a 2011-04-09 kinaba: for(int i=0; i<=nB; ++i,cur*=scoreB) f6f3e6962a 2011-04-09 kinaba: best = max(best, cur); f6f3e6962a 2011-04-09 kinaba: return best; f6f3e6962a 2011-04-09 kinaba: } f6f3e6962a 2011-04-09 kinaba: }; f6f3e6962a 2011-04-09 kinaba: f6f3e6962a 2011-04-09 kinaba: // BEGIN CUT HERE f6f3e6962a 2011-04-09 kinaba: #include <ctime> f6f3e6962a 2011-04-09 kinaba: double start_time; string timer() f6f3e6962a 2011-04-09 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } f6f3e6962a 2011-04-09 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) f6f3e6962a 2011-04-09 kinaba: { os << "{ "; f6f3e6962a 2011-04-09 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) f6f3e6962a 2011-04-09 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } f6f3e6962a 2011-04-09 kinaba: void verify_case(const double& Expected, const double& Received) { f6f3e6962a 2011-04-09 kinaba: bool ok = (abs(Expected - Received) < 1e-9); f6f3e6962a 2011-04-09 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; f6f3e6962a 2011-04-09 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } f6f3e6962a 2011-04-09 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); f6f3e6962a 2011-04-09 kinaba: #define END verify_case(_, FoxPlayingGame().theMax(nA, nB, paramA, paramB));} f6f3e6962a 2011-04-09 kinaba: int main(){ f6f3e6962a 2011-04-09 kinaba: f6f3e6962a 2011-04-09 kinaba: CASE(0) f6f3e6962a 2011-04-09 kinaba: int nA = 5; f6f3e6962a 2011-04-09 kinaba: int nB = 4; f6f3e6962a 2011-04-09 kinaba: int paramA = 3000; f6f3e6962a 2011-04-09 kinaba: int paramB = 2000; f6f3e6962a 2011-04-09 kinaba: double _ = 240.0; f6f3e6962a 2011-04-09 kinaba: END f6f3e6962a 2011-04-09 kinaba: CASE(1) f6f3e6962a 2011-04-09 kinaba: int nA = 3; f6f3e6962a 2011-04-09 kinaba: int nB = 3; f6f3e6962a 2011-04-09 kinaba: int paramA = 2000; f6f3e6962a 2011-04-09 kinaba: int paramB = 100; f6f3e6962a 2011-04-09 kinaba: double _ = 6.0; f6f3e6962a 2011-04-09 kinaba: END f6f3e6962a 2011-04-09 kinaba: CASE(2) f6f3e6962a 2011-04-09 kinaba: int nA = 4; f6f3e6962a 2011-04-09 kinaba: int nB = 3; f6f3e6962a 2011-04-09 kinaba: int paramA = -2000; f6f3e6962a 2011-04-09 kinaba: int paramB = 2000; f6f3e6962a 2011-04-09 kinaba: double _ = -8.0; f6f3e6962a 2011-04-09 kinaba: END f6f3e6962a 2011-04-09 kinaba: CASE(3) f6f3e6962a 2011-04-09 kinaba: int nA = 5; f6f3e6962a 2011-04-09 kinaba: int nB = 5; f6f3e6962a 2011-04-09 kinaba: int paramA = 2000; f6f3e6962a 2011-04-09 kinaba: int paramB = -2000; f6f3e6962a 2011-04-09 kinaba: double _ = 160.0; f6f3e6962a 2011-04-09 kinaba: END f6f3e6962a 2011-04-09 kinaba: CASE(4) f6f3e6962a 2011-04-09 kinaba: int nA = 50; f6f3e6962a 2011-04-09 kinaba: int nB = 50; f6f3e6962a 2011-04-09 kinaba: int paramA = 10000; f6f3e6962a 2011-04-09 kinaba: int paramB = 2000; f6f3e6962a 2011-04-09 kinaba: double _ = 5.62949953421312E17; f6f3e6962a 2011-04-09 kinaba: END f6f3e6962a 2011-04-09 kinaba: CASE(5) f6f3e6962a 2011-04-09 kinaba: int nA = 41; f6f3e6962a 2011-04-09 kinaba: int nB = 34; f6f3e6962a 2011-04-09 kinaba: int paramA = 9876; f6f3e6962a 2011-04-09 kinaba: int paramB = -1234; f6f3e6962a 2011-04-09 kinaba: double _ = 515323.9982341775; f6f3e6962a 2011-04-09 kinaba: END f6f3e6962a 2011-04-09 kinaba: CASE(6) f6f3e6962a 2011-04-09 kinaba: int nA = 23; f6f3e6962a 2011-04-09 kinaba: int nB = 34; f6f3e6962a 2011-04-09 kinaba: int paramA = -9422; f6f3e6962a 2011-04-09 kinaba: int paramB = -180; f6f3e6962a 2011-04-09 kinaba: double _ = 39.00708; f6f3e6962a 2011-04-09 kinaba: END f6f3e6962a 2011-04-09 kinaba: /* f6f3e6962a 2011-04-09 kinaba: CASE(7) f6f3e6962a 2011-04-09 kinaba: int nA = ; f6f3e6962a 2011-04-09 kinaba: int nB = ; f6f3e6962a 2011-04-09 kinaba: int paramA = ; f6f3e6962a 2011-04-09 kinaba: int paramB = ; f6f3e6962a 2011-04-09 kinaba: double _ = ; f6f3e6962a 2011-04-09 kinaba: END f6f3e6962a 2011-04-09 kinaba: */ f6f3e6962a 2011-04-09 kinaba: } f6f3e6962a 2011-04-09 kinaba: // END CUT HERE