f7e7bde312 2012-09-01 kinaba: #include <iostream> f7e7bde312 2012-09-01 kinaba: #include <sstream> f7e7bde312 2012-09-01 kinaba: #include <iomanip> f7e7bde312 2012-09-01 kinaba: #include <vector> f7e7bde312 2012-09-01 kinaba: #include <string> f7e7bde312 2012-09-01 kinaba: #include <map> f7e7bde312 2012-09-01 kinaba: #include <set> f7e7bde312 2012-09-01 kinaba: #include <algorithm> f7e7bde312 2012-09-01 kinaba: #include <numeric> f7e7bde312 2012-09-01 kinaba: #include <iterator> f7e7bde312 2012-09-01 kinaba: #include <functional> f7e7bde312 2012-09-01 kinaba: #include <complex> f7e7bde312 2012-09-01 kinaba: #include <queue> f7e7bde312 2012-09-01 kinaba: #include <stack> f7e7bde312 2012-09-01 kinaba: #include <cmath> f7e7bde312 2012-09-01 kinaba: #include <cassert> f7e7bde312 2012-09-01 kinaba: using namespace std; f7e7bde312 2012-09-01 kinaba: typedef long long LL; f7e7bde312 2012-09-01 kinaba: typedef long double LD; f7e7bde312 2012-09-01 kinaba: typedef complex<LD> CMP; f7e7bde312 2012-09-01 kinaba: f7e7bde312 2012-09-01 kinaba: class PlatypusDuckAndBeaver { public: f7e7bde312 2012-09-01 kinaba: int minimumAnimals(int webbedFeet, int duckBills, int beaverTails) f7e7bde312 2012-09-01 kinaba: { f7e7bde312 2012-09-01 kinaba: // 2 1 0 f7e7bde312 2012-09-01 kinaba: // 4 0 1 f7e7bde312 2012-09-01 kinaba: // 4 1 1 f7e7bde312 2012-09-01 kinaba: for(int c=0 ;; ++c) f7e7bde312 2012-09-01 kinaba: { f7e7bde312 2012-09-01 kinaba: int a = duckBills - c; f7e7bde312 2012-09-01 kinaba: int b = beaverTails - c; f7e7bde312 2012-09-01 kinaba: if(a*2+b*4+c*4 == webbedFeet) f7e7bde312 2012-09-01 kinaba: return a+b+c; f7e7bde312 2012-09-01 kinaba: } f7e7bde312 2012-09-01 kinaba: } f7e7bde312 2012-09-01 kinaba: }; f7e7bde312 2012-09-01 kinaba: f7e7bde312 2012-09-01 kinaba: // BEGIN CUT HERE f7e7bde312 2012-09-01 kinaba: #include <ctime> f7e7bde312 2012-09-01 kinaba: double start_time; string timer() f7e7bde312 2012-09-01 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } f7e7bde312 2012-09-01 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) f7e7bde312 2012-09-01 kinaba: { os << "{ "; f7e7bde312 2012-09-01 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) f7e7bde312 2012-09-01 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } f7e7bde312 2012-09-01 kinaba: void verify_case(const int& Expected, const int& Received) { f7e7bde312 2012-09-01 kinaba: bool ok = (Expected == Received); f7e7bde312 2012-09-01 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; f7e7bde312 2012-09-01 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } f7e7bde312 2012-09-01 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); f7e7bde312 2012-09-01 kinaba: #define END verify_case(_, PlatypusDuckAndBeaver().minimumAnimals(webbedFeet, duckBills, beaverTails));} f7e7bde312 2012-09-01 kinaba: int main(){ f7e7bde312 2012-09-01 kinaba: f7e7bde312 2012-09-01 kinaba: CASE(0) f7e7bde312 2012-09-01 kinaba: int webbedFeet = 4; f7e7bde312 2012-09-01 kinaba: int duckBills = 1; f7e7bde312 2012-09-01 kinaba: int beaverTails = 1; f7e7bde312 2012-09-01 kinaba: int _ = 1; f7e7bde312 2012-09-01 kinaba: END f7e7bde312 2012-09-01 kinaba: CASE(1) f7e7bde312 2012-09-01 kinaba: int webbedFeet = 0; f7e7bde312 2012-09-01 kinaba: int duckBills = 0; f7e7bde312 2012-09-01 kinaba: int beaverTails = 0; f7e7bde312 2012-09-01 kinaba: int _ = 0; f7e7bde312 2012-09-01 kinaba: END f7e7bde312 2012-09-01 kinaba: CASE(2) f7e7bde312 2012-09-01 kinaba: int webbedFeet = 10; f7e7bde312 2012-09-01 kinaba: int duckBills = 2; f7e7bde312 2012-09-01 kinaba: int beaverTails = 2; f7e7bde312 2012-09-01 kinaba: int _ = 3; f7e7bde312 2012-09-01 kinaba: END f7e7bde312 2012-09-01 kinaba: CASE(3) f7e7bde312 2012-09-01 kinaba: int webbedFeet = 60; f7e7bde312 2012-09-01 kinaba: int duckBills = 10; f7e7bde312 2012-09-01 kinaba: int beaverTails = 10; f7e7bde312 2012-09-01 kinaba: int _ = 20; f7e7bde312 2012-09-01 kinaba: END f7e7bde312 2012-09-01 kinaba: CASE(4) f7e7bde312 2012-09-01 kinaba: int webbedFeet = 1000; f7e7bde312 2012-09-01 kinaba: int duckBills = 200; f7e7bde312 2012-09-01 kinaba: int beaverTails = 200; f7e7bde312 2012-09-01 kinaba: int _ = 300; f7e7bde312 2012-09-01 kinaba: END f7e7bde312 2012-09-01 kinaba: /* f7e7bde312 2012-09-01 kinaba: CASE(5) f7e7bde312 2012-09-01 kinaba: int webbedFeet = ; f7e7bde312 2012-09-01 kinaba: int duckBills = ; f7e7bde312 2012-09-01 kinaba: int beaverTails = ; f7e7bde312 2012-09-01 kinaba: int _ = ; f7e7bde312 2012-09-01 kinaba: END f7e7bde312 2012-09-01 kinaba: CASE(6) f7e7bde312 2012-09-01 kinaba: int webbedFeet = ; f7e7bde312 2012-09-01 kinaba: int duckBills = ; f7e7bde312 2012-09-01 kinaba: int beaverTails = ; f7e7bde312 2012-09-01 kinaba: int _ = ; f7e7bde312 2012-09-01 kinaba: END f7e7bde312 2012-09-01 kinaba: */ f7e7bde312 2012-09-01 kinaba: } f7e7bde312 2012-09-01 kinaba: // END CUT HERE