4fd800b3a8 2011-02-23 kinaba: #include <iostream> 4fd800b3a8 2011-02-23 kinaba: #include <sstream> 4fd800b3a8 2011-02-23 kinaba: #include <iomanip> 4fd800b3a8 2011-02-23 kinaba: #include <vector> 4fd800b3a8 2011-02-23 kinaba: #include <string> 4fd800b3a8 2011-02-23 kinaba: #include <map> 4fd800b3a8 2011-02-23 kinaba: #include <set> 4fd800b3a8 2011-02-23 kinaba: #include <algorithm> 4fd800b3a8 2011-02-23 kinaba: #include <numeric> 4fd800b3a8 2011-02-23 kinaba: #include <iterator> 4fd800b3a8 2011-02-23 kinaba: #include <complex> 4fd800b3a8 2011-02-23 kinaba: #include <queue> 4fd800b3a8 2011-02-23 kinaba: #include <stack> 4fd800b3a8 2011-02-23 kinaba: #include <cmath> 4fd800b3a8 2011-02-23 kinaba: using namespace std; 4fd800b3a8 2011-02-23 kinaba: typedef long long LL; 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: typedef int vert; 4fd800b3a8 2011-02-23 kinaba: typedef vert edge; 4fd800b3a8 2011-02-23 kinaba: typedef vector<edge> edges; 4fd800b3a8 2011-02-23 kinaba: typedef vector<edges> graph; 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: bool augment( graph& G, int v, vector<vert>& matchTo, bool visited[] ) 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: for(int i=0; i<G[v].size(); ++i) { 4fd800b3a8 2011-02-23 kinaba: vert u = G[v][i]; 4fd800b3a8 2011-02-23 kinaba: if( visited[u] ) continue; 4fd800b3a8 2011-02-23 kinaba: visited[u] = true; 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: if( matchTo[u]<0 || augment(G, matchTo[u], matchTo, visited) ) 4fd800b3a8 2011-02-23 kinaba: { matchTo[v]=u, matchTo[u]=v; return true; } 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: return false; 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: static const int NV=100; 4fd800b3a8 2011-02-23 kinaba: int biMatch( graph& G, int L ) // [0,L):left, [L,?):right 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: vector<vert> matchTo(G.size(), -1); 4fd800b3a8 2011-02-23 kinaba: int ans = 0; 4fd800b3a8 2011-02-23 kinaba: for(vert v=0; v<L; ++v) { 4fd800b3a8 2011-02-23 kinaba: bool visited[NV] = {}; 4fd800b3a8 2011-02-23 kinaba: if( augment(G, v, matchTo, visited) ) 4fd800b3a8 2011-02-23 kinaba: ++ans; 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: return ans; 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: class HouseProtection 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: public: 4fd800b3a8 2011-02-23 kinaba: double safetyFactor(vector <int> bx, vector <int> by, vector <int> rx, vector <int> ry, int R) 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: double r[50][50]; 4fd800b3a8 2011-02-23 kinaba: set<double> rs; 4fd800b3a8 2011-02-23 kinaba: for(int i=0; i<bx.size(); ++i) 4fd800b3a8 2011-02-23 kinaba: for(int j=0; j<rx.size(); ++j) { 4fd800b3a8 2011-02-23 kinaba: r[i][j] = sqrt((double)(bx[i]-rx[j])*(bx[i]-rx[j]) + (by[i]-ry[j])*(by[i]-ry[j]))/2; 4fd800b3a8 2011-02-23 kinaba: rs.insert( min<double>(r[i][j], R) ); 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: rs.insert(R); 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: double result = 0; 4fd800b3a8 2011-02-23 kinaba: for(set<double>::iterator it=rs.begin(); it!=rs.end(); ++it) 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: double curR = *it; 4fd800b3a8 2011-02-23 kinaba: graph G(bx.size()+rx.size()); 4fd800b3a8 2011-02-23 kinaba: for(int i=0; i<bx.size(); ++i) 4fd800b3a8 2011-02-23 kinaba: for(int j=0; j<rx.size(); ++j) 4fd800b3a8 2011-02-23 kinaba: if( r[i][j] < curR ) { 4fd800b3a8 2011-02-23 kinaba: G[i].push_back( bx.size()+j ); 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: int Num = bx.size() + rx.size() - biMatch( G, bx.size() ); 4fd800b3a8 2011-02-23 kinaba: result = max(result, Num*curR*curR); 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: return result * M_PI; 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: // BEGIN CUT HERE 4fd800b3a8 2011-02-23 kinaba: public: 4fd800b3a8 2011-02-23 kinaba: 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(); } 4fd800b3a8 2011-02-23 kinaba: private: 4fd800b3a8 2011-02-23 kinaba: 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(); } 4fd800b3a8 2011-02-23 kinaba: 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; } } 4fd800b3a8 2011-02-23 kinaba: 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)); } 4fd800b3a8 2011-02-23 kinaba: 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)); } 4fd800b3a8 2011-02-23 kinaba: 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)); } 4fd800b3a8 2011-02-23 kinaba: 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)); } 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: // END CUT HERE 4fd800b3a8 2011-02-23 kinaba: }; 4fd800b3a8 2011-02-23 kinaba: // BEGIN CUT HERE 4fd800b3a8 2011-02-23 kinaba: int main() { 4fd800b3a8 2011-02-23 kinaba: HouseProtection().run_test(-1); 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: // END CUT HERE