Artifact Content
Not logged in

Artifact fc75099a804bb837ecf065219d017da24f9d6def


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

class TheNewHouseDivOne { public:
	double distance(vector <int> x, vector <int> y, int k) 
	{
		double minD = 1e+99;
		for(double X=-50; X<=+50; X+=0.5)
			for(double Y=-50; Y<=+50; Y+=0.5)
			{
				vector<double> d;
				for(int i=0; i<x.size(); ++i)
					d.push_back( abs(x[i]-X) + abs(y[i]-Y) );
				nth_element(d.begin(), d.begin()+k-1, d.end());
				minD = min(minD, d[k-1]);
			}
		return minD;
	}
};

// 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 double& Expected, const double& Received) {
 double diff = Expected - Received; if (diff < 0) diff = -diff; bool ok = (diff < 1e-9);
 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(_, TheNewHouseDivOne().distance(x, y, k));}
int main(){

CASE(0)
	int x_[] = {-1, -1, 1, 1};
	  vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 
	int y_[] = {-1, 1, -1, 1};
	  vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 
	int k = 3; 
	double _ = 2.0; 
END
CASE(1)
	int x_[] = {-1, -1, 1, 1};
	  vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 
	int y_[] = {-1, 1, -1, 1};
	  vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 
	int k = 2; 
	double _ = 1.0; 
END
CASE(2)
	int x_[] = {4, 4, 4, 4, 4, 3, 3, 5, 5};
	  vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 
	int y_[] = {7, 7, 7, 4, 4, 5, 6, 5, 6};
	  vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 
	int k = 9; 
	double _ = 1.5; 
END
CASE(3)
	int x_[] = {30, -15, 24, -23, 43, -8, -6, -47, 23, -11, 43, 6, -18, 44, -46, 16, 32, 31, 13, 9, 22, 25, 4, -44, 38, -41, -20, 41, -35, 7, 25, 39, -36, -20, -5, -38, -15, -22, 0};
	  vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 
	int y_[] = {-45, -7, -33, 31, -8, -33, -20, -14, -50, -48, -31, 35, -24, -31, -11, 41, -41, -11, 46, -1, -5, 5, -39, -26, -40, -9, 16, 38, -30, 34, 46, -17, -27, 33, -38, 28, 46, -16, -46};
	  vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 
	int k = 13; 
	double _ = 32.0; 
END

}
// END CUT HERE