Artifact Content
Not logged in

Artifact ce0cb27aa1496b82235cab41a815e0393b4be357


#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>
#include <cstring>
#ifdef __GNUC__
#include <ext/hash_map>
#define unordered_map __gnu_cxx::hash_map
#else
#include <unordered_map>
#endif
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class Mosquitoes { public:
	int getMaximum(vector <int> xInit, vector <int> v, int R)
	{
		vector< pair<double,double> > 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<tx.size(); ++i) {
			double t = tx[i].first;
			double x = tx[i].second;
			if( t >= 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<double,double> >* 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 <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(_, Mosquitoes().getMaximum(xInit, v, R));}
int main(){

CASE(0)
	int xInit_[] = {1, -1};
	  vector <int> xInit(xInit_, xInit_+sizeof(xInit_)/sizeof(*xInit_)); 
	int v_[] = {1, -1};
	  vector <int> v(v_, v_+sizeof(v_)/sizeof(*v_)); 
	int R = 10; 
	int _ = 2; 
END
CASE(1)
	int xInit_[] = {100, -100};
	  vector <int> xInit(xInit_, xInit_+sizeof(xInit_)/sizeof(*xInit_)); 
	int v_[] = {1, -1};
	  vector <int> v(v_, v_+sizeof(v_)/sizeof(*v_)); 
	int R = 10; 
	int _ = 1; 
END
CASE(2)
	int xInit_[] = {0, -1, 10, -11, 99, -99};
	  vector <int> xInit(xInit_, xInit_+sizeof(xInit_)/sizeof(*xInit_)); 
	int v_[] = {1, -1, -3, 3, 47, -47};
	  vector <int> v(v_, v_+sizeof(v_)/sizeof(*v_)); 
	int R = 3; 
	int _ = 4; 
END
CASE(3)
	int xInit_[] = {5};
	  vector <int> xInit(xInit_, xInit_+sizeof(xInit_)/sizeof(*xInit_)); 
	int v_[] = {2};
	  vector <int> v(v_, v_+sizeof(v_)/sizeof(*v_)); 
	int R = 8; 
	int _ = 1; 
END
CASE(4)
	int xInit_[] = {12,34,56,78,90};
	  vector <int> xInit(xInit_, xInit_+sizeof(xInit_)/sizeof(*xInit_)); 
	int v_[] = {-1,2,-3,4,-5};
	  vector <int> v(v_, v_+sizeof(v_)/sizeof(*v_)); 
	int R = 6; 
	int _ = 3; 
END
CASE(5)
	int xInit_[] = {-29, -27};
	  vector <int> xInit(xInit_, xInit_+sizeof(xInit_)/sizeof(*xInit_)); 
	int v_[] = {25, 61};
	  vector <int> v(v_, v_+sizeof(v_)/sizeof(*v_)); 
	int R = 7; 
	int _ = 2; 
END
/*
CASE(6)
	int xInit_[] = ;
	  vector <int> xInit(xInit_, xInit_+sizeof(xInit_)/sizeof(*xInit_)); 
	int v_[] = ;
	  vector <int> v(v_, v_+sizeof(v_)/sizeof(*v_)); 
	int R = ; 
	int _ = ; 
END
*/
}
// END CUT HERE