ADDED SRM/528/2C.cpp Index: SRM/528/2C.cpp ================================================================== --- SRM/528/2C.cpp +++ SRM/528/2C.cpp @@ -0,0 +1,154 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef __GNUC__ +#include +#define unordered_map __gnu_cxx::hash_map +#else +#include +#endif +using namespace std; +typedef long long LL; +typedef complex CMP; + +class Mosquitoes { public: + int getMaximum(vector xInit, vector v, int R) + { + vector< pair > tx; + for (int i = 0; i < xInit.size(); i++) + for (int j = i+1; j < xInit.size(); j++) + critical_points(xInit[i], v[i], xInit[j], v[j], R, &tx); + + int best = 1; + for(int i=0; i= 0 ) { + int cnt = 0; + for (int k = 0; k < xInit.size(); k++) + if( is_in(xInit[k], v[k], t, x, R) ) + ++cnt; + best = max(best, cnt); + } + } + return best; + } + + void critical_points(double x1, double v1, double x2, double v2, double R, + vector< pair >* tx) + { + // Compute t such that | (x1 + t v1) - (x2 - t v2) | = 2R + double x = x1 - x2; + double v = v1 - v2; + if( v == 0 ) { + if( abs(x) <= 2*R ) + tx->push_back( make_pair(0, (x1+x2)/2) ); + } else { + double t1 = (2*R - x) / v; + double t2 = (2*R + x) / (-v); + tx->push_back( make_pair(t1, (func(x1,v1,t1)+func(x2,v2,t1))/2) ); + tx->push_back( make_pair(t2, (func(x1,v1,t2)+func(x2,v2,t2))/2) ); + } + } + + double func(double x, double v, double t) + { + return x + v*t; + } + + bool is_in(double x, double v, double t, double c, double R) + { + return abs(func(x,v,t) - c) <= R + 1e-8; + } +}; + +// BEGIN CUT HERE +#include +double start_time; string timer() + { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } +template ostream& operator<<(ostream& os, const vector& v) + { os << "{ "; + for(typename vector::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(_, Mosquitoes().getMaximum(xInit, v, R));} +int main(){ + +CASE(0) + int xInit_[] = {1, -1}; + vector xInit(xInit_, xInit_+sizeof(xInit_)/sizeof(*xInit_)); + int v_[] = {1, -1}; + vector v(v_, v_+sizeof(v_)/sizeof(*v_)); + int R = 10; + int _ = 2; +END +CASE(1) + int xInit_[] = {100, -100}; + vector xInit(xInit_, xInit_+sizeof(xInit_)/sizeof(*xInit_)); + int v_[] = {1, -1}; + vector v(v_, v_+sizeof(v_)/sizeof(*v_)); + int R = 10; + int _ = 1; +END +CASE(2) + int xInit_[] = {0, -1, 10, -11, 99, -99}; + vector xInit(xInit_, xInit_+sizeof(xInit_)/sizeof(*xInit_)); + int v_[] = {1, -1, -3, 3, 47, -47}; + vector v(v_, v_+sizeof(v_)/sizeof(*v_)); + int R = 3; + int _ = 4; +END +CASE(3) + int xInit_[] = {5}; + vector xInit(xInit_, xInit_+sizeof(xInit_)/sizeof(*xInit_)); + int v_[] = {2}; + vector v(v_, v_+sizeof(v_)/sizeof(*v_)); + int R = 8; + int _ = 1; +END +CASE(4) + int xInit_[] = {12,34,56,78,90}; + vector xInit(xInit_, xInit_+sizeof(xInit_)/sizeof(*xInit_)); + int v_[] = {-1,2,-3,4,-5}; + vector v(v_, v_+sizeof(v_)/sizeof(*v_)); + int R = 6; + int _ = 3; +END +CASE(5) + int xInit_[] = {-29, -27}; + vector xInit(xInit_, xInit_+sizeof(xInit_)/sizeof(*xInit_)); + int v_[] = {25, 61}; + vector v(v_, v_+sizeof(v_)/sizeof(*v_)); + int R = 7; + int _ = 2; +END +/* +CASE(6) + int xInit_[] = ; + vector xInit(xInit_, xInit_+sizeof(xInit_)/sizeof(*xInit_)); + int v_[] = ; + vector v(v_, v_+sizeof(v_)/sizeof(*v_)); + int R = ; + int _ = ; +END +*/ +} +// END CUT HERE