File Annotation
Not logged in
c9008fc667 2012-08-08        kinaba: #include <iostream>
c9008fc667 2012-08-08        kinaba: #include <sstream>
c9008fc667 2012-08-08        kinaba: #include <iomanip>
c9008fc667 2012-08-08        kinaba: #include <vector>
c9008fc667 2012-08-08        kinaba: #include <string>
c9008fc667 2012-08-08        kinaba: #include <map>
c9008fc667 2012-08-08        kinaba: #include <set>
c9008fc667 2012-08-08        kinaba: #include <algorithm>
c9008fc667 2012-08-08        kinaba: #include <numeric>
c9008fc667 2012-08-08        kinaba: #include <iterator>
c9008fc667 2012-08-08        kinaba: #include <functional>
c9008fc667 2012-08-08        kinaba: #include <complex>
c9008fc667 2012-08-08        kinaba: #include <queue>
c9008fc667 2012-08-08        kinaba: #include <stack>
c9008fc667 2012-08-08        kinaba: #include <cmath>
c9008fc667 2012-08-08        kinaba: #include <cassert>
c9008fc667 2012-08-08        kinaba: using namespace std;
c9008fc667 2012-08-08        kinaba: typedef long long LL;
c9008fc667 2012-08-08        kinaba: typedef long double LD;
c9008fc667 2012-08-08        kinaba: typedef complex<LD> CMP;
c9008fc667 2012-08-08        kinaba: 
c9008fc667 2012-08-08        kinaba: typedef int           vert;
c9008fc667 2012-08-08        kinaba: typedef vert          edge;
c9008fc667 2012-08-08        kinaba: typedef vector<edge>  edges;
c9008fc667 2012-08-08        kinaba: typedef vector<edges> graph;
c9008fc667 2012-08-08        kinaba: 
c9008fc667 2012-08-08        kinaba: bool augment( graph& G, int v, vector<vert>& matchTo, bool visited[] )
c9008fc667 2012-08-08        kinaba: {
c9008fc667 2012-08-08        kinaba: 	for(int i=0; i<G[v].size(); ++i) {
c9008fc667 2012-08-08        kinaba: 		vert u = G[v][i];
c9008fc667 2012-08-08        kinaba: 		if( visited[u] ) continue;
c9008fc667 2012-08-08        kinaba: 		visited[u] = true;
c9008fc667 2012-08-08        kinaba: 
c9008fc667 2012-08-08        kinaba: 		if( matchTo[u]<0 || augment(G, matchTo[u], matchTo, visited) )
c9008fc667 2012-08-08        kinaba: 			{ matchTo[v]=u, matchTo[u]=v; return true; }
c9008fc667 2012-08-08        kinaba: 	}
c9008fc667 2012-08-08        kinaba: 	return false;
c9008fc667 2012-08-08        kinaba: }
c9008fc667 2012-08-08        kinaba: 
c9008fc667 2012-08-08        kinaba: template<int NV>
c9008fc667 2012-08-08        kinaba: int biMatch( graph& G, int L ) // [0,L):left, [L,?):right
c9008fc667 2012-08-08        kinaba: {
c9008fc667 2012-08-08        kinaba: 	vector<vert> matchTo(G.size(), -1);
c9008fc667 2012-08-08        kinaba: 	int ans = 0;
c9008fc667 2012-08-08        kinaba: 	for(vert v=0; v<L; ++v) {
c9008fc667 2012-08-08        kinaba: 		bool visited[NV] = {};
c9008fc667 2012-08-08        kinaba: 		if( augment(G, v, matchTo, visited) )
c9008fc667 2012-08-08        kinaba: 			++ans;
c9008fc667 2012-08-08        kinaba: 	}
c9008fc667 2012-08-08        kinaba: 	return ans;
c9008fc667 2012-08-08        kinaba: }
c9008fc667 2012-08-08        kinaba: 
c9008fc667 2012-08-08        kinaba: class PointyWizardHats { public:
c9008fc667 2012-08-08        kinaba: 	int getNumHats(vector <int> topHeight, vector <int> topRadius, vector <int> bottomHeight, vector <int> bottomRadius)
c9008fc667 2012-08-08        kinaba: 	{
c9008fc667 2012-08-08        kinaba: 		int L = topHeight.size();
c9008fc667 2012-08-08        kinaba: 		int R = bottomHeight.size();
c9008fc667 2012-08-08        kinaba: 		graph G(L+R);
c9008fc667 2012-08-08        kinaba: 		for(int i=0; i<L; ++i)
c9008fc667 2012-08-08        kinaba: 			for(int k=0; k<R; ++k)
c9008fc667 2012-08-08        kinaba: 				if( ok(topHeight[i], topRadius[i], bottomHeight[k], bottomRadius[k]) )
c9008fc667 2012-08-08        kinaba: 					G[i].push_back(L+k);
c9008fc667 2012-08-08        kinaba: 		return biMatch<100>(G, L);
c9008fc667 2012-08-08        kinaba: 	}
c9008fc667 2012-08-08        kinaba: 
c9008fc667 2012-08-08        kinaba: 	bool ok(int th, int tr, int bh, int br)
c9008fc667 2012-08-08        kinaba: 	{
c9008fc667 2012-08-08        kinaba: 		if( th*br > bh*tr ) {
c9008fc667 2012-08-08        kinaba: 			return br > tr;
c9008fc667 2012-08-08        kinaba: 		}
c9008fc667 2012-08-08        kinaba: 		return false;
c9008fc667 2012-08-08        kinaba: 	}
c9008fc667 2012-08-08        kinaba: };
c9008fc667 2012-08-08        kinaba: 
c9008fc667 2012-08-08        kinaba: // BEGIN CUT HERE
c9008fc667 2012-08-08        kinaba: #include <ctime>
c9008fc667 2012-08-08        kinaba: double start_time; string timer()
c9008fc667 2012-08-08        kinaba:  { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
c9008fc667 2012-08-08        kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
c9008fc667 2012-08-08        kinaba:  { os << "{ ";
c9008fc667 2012-08-08        kinaba:    for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
c9008fc667 2012-08-08        kinaba:    os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
c9008fc667 2012-08-08        kinaba: void verify_case(const int& Expected, const int& Received) {
c9008fc667 2012-08-08        kinaba:  bool ok = (Expected == Received);
c9008fc667 2012-08-08        kinaba:  if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
c9008fc667 2012-08-08        kinaba:  cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
c9008fc667 2012-08-08        kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
c9008fc667 2012-08-08        kinaba: #define END	 verify_case(_, PointyWizardHats().getNumHats(topHeight, topRadius, bottomHeight, bottomRadius));}
c9008fc667 2012-08-08        kinaba: int main(){
c9008fc667 2012-08-08        kinaba: 
c9008fc667 2012-08-08        kinaba: CASE(0)
c9008fc667 2012-08-08        kinaba: 	int topHeight_[] = {30};
c9008fc667 2012-08-08        kinaba: 	  vector <int> topHeight(topHeight_, topHeight_+sizeof(topHeight_)/sizeof(*topHeight_));
c9008fc667 2012-08-08        kinaba: 	int topRadius_[] = {3};
c9008fc667 2012-08-08        kinaba: 	  vector <int> topRadius(topRadius_, topRadius_+sizeof(topRadius_)/sizeof(*topRadius_));
c9008fc667 2012-08-08        kinaba: 	int bottomHeight_[] = {3};
c9008fc667 2012-08-08        kinaba: 	  vector <int> bottomHeight(bottomHeight_, bottomHeight_+sizeof(bottomHeight_)/sizeof(*bottomHeight_));
c9008fc667 2012-08-08        kinaba: 	int bottomRadius_[] = {30};
c9008fc667 2012-08-08        kinaba: 	  vector <int> bottomRadius(bottomRadius_, bottomRadius_+sizeof(bottomRadius_)/sizeof(*bottomRadius_));
c9008fc667 2012-08-08        kinaba: 	int _ = 1;
c9008fc667 2012-08-08        kinaba: END
c9008fc667 2012-08-08        kinaba: CASE(1)
c9008fc667 2012-08-08        kinaba: 	int topHeight_[] = {4,4};
c9008fc667 2012-08-08        kinaba: 	  vector <int> topHeight(topHeight_, topHeight_+sizeof(topHeight_)/sizeof(*topHeight_));
c9008fc667 2012-08-08        kinaba: 	int topRadius_[] = {4,3};
c9008fc667 2012-08-08        kinaba: 	  vector <int> topRadius(topRadius_, topRadius_+sizeof(topRadius_)/sizeof(*topRadius_));
c9008fc667 2012-08-08        kinaba: 	int bottomHeight_[] = {5,12};
c9008fc667 2012-08-08        kinaba: 	  vector <int> bottomHeight(bottomHeight_, bottomHeight_+sizeof(bottomHeight_)/sizeof(*bottomHeight_));
c9008fc667 2012-08-08        kinaba: 	int bottomRadius_[] = {5,4};
c9008fc667 2012-08-08        kinaba: 	  vector <int> bottomRadius(bottomRadius_, bottomRadius_+sizeof(bottomRadius_)/sizeof(*bottomRadius_));
c9008fc667 2012-08-08        kinaba: 	int _ = 1;
c9008fc667 2012-08-08        kinaba: END
c9008fc667 2012-08-08        kinaba: CASE(2)
c9008fc667 2012-08-08        kinaba: 	int topHeight_[] = {3};
c9008fc667 2012-08-08        kinaba: 	  vector <int> topHeight(topHeight_, topHeight_+sizeof(topHeight_)/sizeof(*topHeight_));
c9008fc667 2012-08-08        kinaba: 	int topRadius_[] = {3};
c9008fc667 2012-08-08        kinaba: 	  vector <int> topRadius(topRadius_, topRadius_+sizeof(topRadius_)/sizeof(*topRadius_));
c9008fc667 2012-08-08        kinaba: 	int bottomHeight_[] = {1,1};
c9008fc667 2012-08-08        kinaba: 	  vector <int> bottomHeight(bottomHeight_, bottomHeight_+sizeof(bottomHeight_)/sizeof(*bottomHeight_));
c9008fc667 2012-08-08        kinaba: 	int bottomRadius_[] = {2,4};
c9008fc667 2012-08-08        kinaba: 	  vector <int> bottomRadius(bottomRadius_, bottomRadius_+sizeof(bottomRadius_)/sizeof(*bottomRadius_));
c9008fc667 2012-08-08        kinaba: 	int _ = 1;
c9008fc667 2012-08-08        kinaba: END
c9008fc667 2012-08-08        kinaba: CASE(3)
c9008fc667 2012-08-08        kinaba: 	int topHeight_[] = {10,10};
c9008fc667 2012-08-08        kinaba: 	  vector <int> topHeight(topHeight_, topHeight_+sizeof(topHeight_)/sizeof(*topHeight_));
c9008fc667 2012-08-08        kinaba: 	int topRadius_[] = {2,5};
c9008fc667 2012-08-08        kinaba: 	  vector <int> topRadius(topRadius_, topRadius_+sizeof(topRadius_)/sizeof(*topRadius_));
c9008fc667 2012-08-08        kinaba: 	int bottomHeight_[] = {2,9};
c9008fc667 2012-08-08        kinaba: 	  vector <int> bottomHeight(bottomHeight_, bottomHeight_+sizeof(bottomHeight_)/sizeof(*bottomHeight_));
c9008fc667 2012-08-08        kinaba: 	int bottomRadius_[] = {3,6};
c9008fc667 2012-08-08        kinaba: 	  vector <int> bottomRadius(bottomRadius_, bottomRadius_+sizeof(bottomRadius_)/sizeof(*bottomRadius_));
c9008fc667 2012-08-08        kinaba: 	int _ = 2;
c9008fc667 2012-08-08        kinaba: END
c9008fc667 2012-08-08        kinaba: CASE(4)
c9008fc667 2012-08-08        kinaba: 	int topHeight_[] = {3,4,5};
c9008fc667 2012-08-08        kinaba: 	  vector <int> topHeight(topHeight_, topHeight_+sizeof(topHeight_)/sizeof(*topHeight_));
c9008fc667 2012-08-08        kinaba: 	int topRadius_[] = {5,4,3};
c9008fc667 2012-08-08        kinaba: 	  vector <int> topRadius(topRadius_, topRadius_+sizeof(topRadius_)/sizeof(*topRadius_));
c9008fc667 2012-08-08        kinaba: 	int bottomHeight_[] = {3,4,5};
c9008fc667 2012-08-08        kinaba: 	  vector <int> bottomHeight(bottomHeight_, bottomHeight_+sizeof(bottomHeight_)/sizeof(*bottomHeight_));
c9008fc667 2012-08-08        kinaba: 	int bottomRadius_[] = {3,8,5};
c9008fc667 2012-08-08        kinaba: 	  vector <int> bottomRadius(bottomRadius_, bottomRadius_+sizeof(bottomRadius_)/sizeof(*bottomRadius_));
c9008fc667 2012-08-08        kinaba: 	int _ = 2;
c9008fc667 2012-08-08        kinaba: END
c9008fc667 2012-08-08        kinaba: CASE(5)
c9008fc667 2012-08-08        kinaba: 	int topHeight_[] = {1,2,3,4,5};
c9008fc667 2012-08-08        kinaba: 	  vector <int> topHeight(topHeight_, topHeight_+sizeof(topHeight_)/sizeof(*topHeight_));
c9008fc667 2012-08-08        kinaba: 	int topRadius_[] = {2,3,4,5,6};
c9008fc667 2012-08-08        kinaba: 	  vector <int> topRadius(topRadius_, topRadius_+sizeof(topRadius_)/sizeof(*topRadius_));
c9008fc667 2012-08-08        kinaba: 	int bottomHeight_[] = {2,3,4,5,6};
c9008fc667 2012-08-08        kinaba: 	  vector <int> bottomHeight(bottomHeight_, bottomHeight_+sizeof(bottomHeight_)/sizeof(*bottomHeight_));
c9008fc667 2012-08-08        kinaba: 	int bottomRadius_[] = {1,2,3,4,5};
c9008fc667 2012-08-08        kinaba: 	  vector <int> bottomRadius(bottomRadius_, bottomRadius_+sizeof(bottomRadius_)/sizeof(*bottomRadius_));
c9008fc667 2012-08-08        kinaba: 	int _ = 0;
c9008fc667 2012-08-08        kinaba: END
c9008fc667 2012-08-08        kinaba: CASE(6)
c9008fc667 2012-08-08        kinaba: 	int topHeight_[] = {123,214,232,323,342,343};
c9008fc667 2012-08-08        kinaba: 	  vector <int> topHeight(topHeight_, topHeight_+sizeof(topHeight_)/sizeof(*topHeight_));
c9008fc667 2012-08-08        kinaba: 	int topRadius_[] = {123,123,232,123,323,434};
c9008fc667 2012-08-08        kinaba: 	  vector <int> topRadius(topRadius_, topRadius_+sizeof(topRadius_)/sizeof(*topRadius_));
c9008fc667 2012-08-08        kinaba: 	int bottomHeight_[] = {545,322,123,545,777,999};
c9008fc667 2012-08-08        kinaba: 	  vector <int> bottomHeight(bottomHeight_, bottomHeight_+sizeof(bottomHeight_)/sizeof(*bottomHeight_));
c9008fc667 2012-08-08        kinaba: 	int bottomRadius_[] = {323,443,123,656,767,888};
c9008fc667 2012-08-08        kinaba: 	  vector <int> bottomRadius(bottomRadius_, bottomRadius_+sizeof(bottomRadius_)/sizeof(*bottomRadius_));
c9008fc667 2012-08-08        kinaba: 	int _ = 5;
c9008fc667 2012-08-08        kinaba: END
c9008fc667 2012-08-08        kinaba: CASE(7)
c9008fc667 2012-08-08        kinaba: 	int topHeight_[] = {999,999,999,10000,10000,10000};
c9008fc667 2012-08-08        kinaba: 	  vector <int> topHeight(topHeight_, topHeight_+sizeof(topHeight_)/sizeof(*topHeight_));
c9008fc667 2012-08-08        kinaba: 	int topRadius_[] = {10000,10000,10000,1,2,3};
c9008fc667 2012-08-08        kinaba: 	  vector <int> topRadius(topRadius_, topRadius_+sizeof(topRadius_)/sizeof(*topRadius_));
c9008fc667 2012-08-08        kinaba: 	int bottomHeight_[] = {2324,2323,234,5454,323,232};
c9008fc667 2012-08-08        kinaba: 	  vector <int> bottomHeight(bottomHeight_, bottomHeight_+sizeof(bottomHeight_)/sizeof(*bottomHeight_));
c9008fc667 2012-08-08        kinaba: 	int bottomRadius_[] = {1,2,3222,434,5454,23};
c9008fc667 2012-08-08        kinaba: 	  vector <int> bottomRadius(bottomRadius_, bottomRadius_+sizeof(bottomRadius_)/sizeof(*bottomRadius_));
c9008fc667 2012-08-08        kinaba: 	int _ = 3;
c9008fc667 2012-08-08        kinaba: END
c9008fc667 2012-08-08        kinaba: /*
c9008fc667 2012-08-08        kinaba: CASE(8)
c9008fc667 2012-08-08        kinaba: 	int topHeight_[] = ;
c9008fc667 2012-08-08        kinaba: 	  vector <int> topHeight(topHeight_, topHeight_+sizeof(topHeight_)/sizeof(*topHeight_));
c9008fc667 2012-08-08        kinaba: 	int topRadius_[] = ;
c9008fc667 2012-08-08        kinaba: 	  vector <int> topRadius(topRadius_, topRadius_+sizeof(topRadius_)/sizeof(*topRadius_));
c9008fc667 2012-08-08        kinaba: 	int bottomHeight_[] = ;
c9008fc667 2012-08-08        kinaba: 	  vector <int> bottomHeight(bottomHeight_, bottomHeight_+sizeof(bottomHeight_)/sizeof(*bottomHeight_));
c9008fc667 2012-08-08        kinaba: 	int bottomRadius_[] = ;
c9008fc667 2012-08-08        kinaba: 	  vector <int> bottomRadius(bottomRadius_, bottomRadius_+sizeof(bottomRadius_)/sizeof(*bottomRadius_));
c9008fc667 2012-08-08        kinaba: 	int _ = ;
c9008fc667 2012-08-08        kinaba: END
c9008fc667 2012-08-08        kinaba: CASE(9)
c9008fc667 2012-08-08        kinaba: 	int topHeight_[] = ;
c9008fc667 2012-08-08        kinaba: 	  vector <int> topHeight(topHeight_, topHeight_+sizeof(topHeight_)/sizeof(*topHeight_));
c9008fc667 2012-08-08        kinaba: 	int topRadius_[] = ;
c9008fc667 2012-08-08        kinaba: 	  vector <int> topRadius(topRadius_, topRadius_+sizeof(topRadius_)/sizeof(*topRadius_));
c9008fc667 2012-08-08        kinaba: 	int bottomHeight_[] = ;
c9008fc667 2012-08-08        kinaba: 	  vector <int> bottomHeight(bottomHeight_, bottomHeight_+sizeof(bottomHeight_)/sizeof(*bottomHeight_));
c9008fc667 2012-08-08        kinaba: 	int bottomRadius_[] = ;
c9008fc667 2012-08-08        kinaba: 	  vector <int> bottomRadius(bottomRadius_, bottomRadius_+sizeof(bottomRadius_)/sizeof(*bottomRadius_));
c9008fc667 2012-08-08        kinaba: 	int _ = ;
c9008fc667 2012-08-08        kinaba: END
c9008fc667 2012-08-08        kinaba: */
c9008fc667 2012-08-08        kinaba: }
c9008fc667 2012-08-08        kinaba: // END CUT HERE