Artifact Content
Not logged in

Artifact 438fa969580e81130e6af148dca10cf86a6e570e


#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>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef complex<LD> CMP;

class PlatypusDuckAndBeaver { public:
	int minimumAnimals(int webbedFeet, int duckBills, int beaverTails)
	{
		// 2 1 0
		// 4 0 1
		// 4 1 1
		for(int c=0 ;; ++c)
		{
			int a = duckBills - c;
			int b = beaverTails - c;
			if(a*2+b*4+c*4 == webbedFeet)
				return a+b+c;
		}
	}
};

// 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 int& Expected, const int& 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(_, PlatypusDuckAndBeaver().minimumAnimals(webbedFeet, duckBills, beaverTails));}
int main(){

CASE(0)
	int webbedFeet = 4; 
	int duckBills = 1; 
	int beaverTails = 1; 
	int _ = 1; 
END
CASE(1)
	int webbedFeet = 0; 
	int duckBills = 0; 
	int beaverTails = 0; 
	int _ = 0; 
END
CASE(2)
	int webbedFeet = 10; 
	int duckBills = 2; 
	int beaverTails = 2; 
	int _ = 3; 
END
CASE(3)
	int webbedFeet = 60; 
	int duckBills = 10; 
	int beaverTails = 10; 
	int _ = 20; 
END
CASE(4)
	int webbedFeet = 1000; 
	int duckBills = 200; 
	int beaverTails = 200; 
	int _ = 300; 
END
/*
CASE(5)
	int webbedFeet = ; 
	int duckBills = ; 
	int beaverTails = ; 
	int _ = ; 
END
CASE(6)
	int webbedFeet = ; 
	int duckBills = ; 
	int beaverTails = ; 
	int _ = ; 
END
*/
}
// END CUT HERE