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