Artifact Content
Not logged in

Artifact 9cb81db248e7a64cc49923c44cd1a47dcf3ca888


#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;
typedef long long LL;

typedef int           vert;
typedef vert          edge;
typedef vector<edge>  edges;
typedef vector<edges> graph;

bool augment( graph& G, int v, vector<vert>& matchTo, bool visited[] )
{
	for(int i=0; i<G[v].size(); ++i) {
		vert u = G[v][i];
		if( visited[u] ) continue;
		visited[u] = true;

		if( matchTo[u]<0 || augment(G, matchTo[u], matchTo, visited) )
			{ matchTo[v]=u, matchTo[u]=v; return true; }
	}
	return false;
}

static const int NV=100;
int biMatch( graph& G, int L ) // [0,L):left, [L,?):right
{
	vector<vert> matchTo(G.size(), -1);
	int ans = 0;
	for(vert v=0; v<L; ++v) {
		bool visited[NV] = {};
		if( augment(G, v, matchTo, visited) )
			++ans;
	}
	return ans;
}

class HouseProtection
{
public:
	double safetyFactor(vector <int> bx, vector <int> by, vector <int> rx, vector <int> ry, int R) 
	{
		double r[50][50];
		set<double> rs;
		for(int i=0; i<bx.size(); ++i)
		for(int j=0; j<rx.size(); ++j) {
			r[i][j] = sqrt((double)(bx[i]-rx[j])*(bx[i]-rx[j]) + (by[i]-ry[j])*(by[i]-ry[j]))/2;
			rs.insert( min<double>(r[i][j], R) );
		}
		rs.insert(R);

		double result = 0;
		for(set<double>::iterator it=rs.begin(); it!=rs.end(); ++it)
		{
			double curR = *it;
			graph G(bx.size()+rx.size());
			for(int i=0; i<bx.size(); ++i)
			for(int j=0; j<rx.size(); ++j)
				if( r[i][j] < curR ) {
					G[i].push_back( bx.size()+j );
				}
			int Num = bx.size() + rx.size() - biMatch( G, bx.size() );
			result = max(result, Num*curR*curR);
		}
		return result * M_PI;
	}

// BEGIN CUT HERE
	public:
	void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0(); if ((Case == -1) || (Case == 1)) test_case_1(); if ((Case == -1) || (Case == 2)) test_case_2(); if ((Case == -1) || (Case == 3)) test_case_3(); }
	private:
	template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
	void verify_case(int Case, const double &Expected, const double &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } }
	void test_case_0() { int Arr0[] = { 0, 4 }; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arr1[] = { 0, 0 }; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); int Arr2[] = { 2, 1 }; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0]))); int Arr3[] = { 2, -1 }; vector <int> Arg3(Arr3, Arr3 + (sizeof(Arr3) / sizeof(Arr3[0]))); int Arg4 = 1; double Arg5 = 9.42477796076938; verify_case(0, Arg5, safetyFactor(Arg0, Arg1, Arg2, Arg3, Arg4)); }
	void test_case_1() { int Arr0[] = { 1 }; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arr1[] = { 1 }; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); int Arr2[] = { 1 }; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0]))); int Arr3[] = { 1 }; vector <int> Arg3(Arr3, Arr3 + (sizeof(Arr3) / sizeof(Arr3[0]))); int Arg4 = 5; double Arg5 = 78.53981633974483; verify_case(1, Arg5, safetyFactor(Arg0, Arg1, Arg2, Arg3, Arg4)); }
	void test_case_2() { int Arr0[] = { 0 }; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arr1[] = { 0 }; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); int Arr2[] = { 100 }; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0]))); int Arr3[] = { 0 }; vector <int> Arg3(Arr3, Arr3 + (sizeof(Arr3) / sizeof(Arr3[0]))); int Arg4 = 51; double Arg5 = 15707.963267948966; verify_case(2, Arg5, safetyFactor(Arg0, Arg1, Arg2, Arg3, Arg4)); }
	void test_case_3() { int Arr0[] = { 23, 29, 29, 35 }; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arr1[] = { 77, 79, 75, 77 }; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); int Arr2[] = { 26, 26, 32 }; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0]))); int Arr3[] = { 78, 76, 76 }; vector <int> Arg3(Arr3, Arr3 + (sizeof(Arr3) / sizeof(Arr3[0]))); int Arg4 = 3; double Arg5 = 113.09733552923255; verify_case(3, Arg5, safetyFactor(Arg0, Arg1, Arg2, Arg3, Arg4)); }

// END CUT HERE
};
// BEGIN CUT HERE 
int main() {
	HouseProtection().run_test(-1);
}
// END CUT HERE