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 <functional> 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: #include <cassert> 4fd800b3a8 2011-02-23 kinaba: #include <cstring> 4fd800b3a8 2011-02-23 kinaba: using namespace std; 4fd800b3a8 2011-02-23 kinaba: typedef long long LL; 4fd800b3a8 2011-02-23 kinaba: typedef complex<double> CMP; 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: class TheChroniclesOfAmber { public: 4fd800b3a8 2011-02-23 kinaba: double minimumTime(vector <int> princeX, vector <int> princeY, vector <int> destinationX, vector <int> destinationY) 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: int N = princeX.size(); 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: // d[s][g] := the distance from prince[s] to dest[g] 4fd800b3a8 2011-02-23 kinaba: vector< vector<double> > d(N, vector<double>(N)); 4fd800b3a8 2011-02-23 kinaba: for(int s=0; s<N; ++s) 4fd800b3a8 2011-02-23 kinaba: for(int g=0; g<N; ++g) 4fd800b3a8 2011-02-23 kinaba: d[s][g] = hypot(princeX[s]-destinationX[g], princeY[s]-destinationY[g]); 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: // no teleportation 4fd800b3a8 2011-02-23 kinaba: double noTelepo = 0; 4fd800b3a8 2011-02-23 kinaba: for(int i=0; i<N; ++i) 4fd800b3a8 2011-02-23 kinaba: noTelepo = max(noTelepo, d[i][i]); 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: // with teleportation: at least one position must be empty 4fd800b3a8 2011-02-23 kinaba: double answer = noTelepo; 4fd800b3a8 2011-02-23 kinaba: for(int unused_s=0; unused_s<N; ++unused_s) { 4fd800b3a8 2011-02-23 kinaba: double withTelepo = 0; 4fd800b3a8 2011-02-23 kinaba: for(int g=0; g<N; ++g) { // for each goal 4fd800b3a8 2011-02-23 kinaba: double t = 1e+300; 4fd800b3a8 2011-02-23 kinaba: for(int s=0; s<N; ++s) if( s != unused_s ) 4fd800b3a8 2011-02-23 kinaba: t = min(t, d[s][g]); // find the nearest starting point 4fd800b3a8 2011-02-23 kinaba: withTelepo = max(withTelepo, t); 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: answer = min(answer, withTelepo); // take the minimum 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: return answer; 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: }; 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: // BEGIN CUT HERE 4fd800b3a8 2011-02-23 kinaba: #include <ctime> 4fd800b3a8 2011-02-23 kinaba: double start_time; string timer() 4fd800b3a8 2011-02-23 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 4fd800b3a8 2011-02-23 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 4fd800b3a8 2011-02-23 kinaba: { os << "{ "; 4fd800b3a8 2011-02-23 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 4fd800b3a8 2011-02-23 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 4fd800b3a8 2011-02-23 kinaba: void verify_case(const double& Expected, const double& Received) { 4fd800b3a8 2011-02-23 kinaba: bool ok = (abs(Expected - Received) < 1e-9); 4fd800b3a8 2011-02-23 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 4fd800b3a8 2011-02-23 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 4fd800b3a8 2011-02-23 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 4fd800b3a8 2011-02-23 kinaba: #define END verify_case(_, TheChroniclesOfAmber().minimumTime(princeX, princeY, destinationX, destinationY));} 4fd800b3a8 2011-02-23 kinaba: int main(){ 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: CASE(0) 4fd800b3a8 2011-02-23 kinaba: int princeX_[] = {1,5,5}; 4fd800b3a8 2011-02-23 kinaba: vector <int> princeX(princeX_, princeX_+sizeof(princeX_)/sizeof(*princeX_)); 4fd800b3a8 2011-02-23 kinaba: int princeY_[] = {0,0,0}; 4fd800b3a8 2011-02-23 kinaba: vector <int> princeY(princeY_, princeY_+sizeof(princeY_)/sizeof(*princeY_)); 4fd800b3a8 2011-02-23 kinaba: int destinationX_[] = {1,1,0}; 4fd800b3a8 2011-02-23 kinaba: vector <int> destinationX(destinationX_, destinationX_+sizeof(destinationX_)/sizeof(*destinationX_)); 4fd800b3a8 2011-02-23 kinaba: int destinationY_[] = {4,2,3}; 4fd800b3a8 2011-02-23 kinaba: vector <int> destinationY(destinationY_, destinationY_+sizeof(destinationY_)/sizeof(*destinationY_)); 4fd800b3a8 2011-02-23 kinaba: double _ = 4.0; 4fd800b3a8 2011-02-23 kinaba: END 4fd800b3a8 2011-02-23 kinaba: CASE(1) 4fd800b3a8 2011-02-23 kinaba: int princeX_[] = {0,0,0}; 4fd800b3a8 2011-02-23 kinaba: vector <int> princeX(princeX_, princeX_+sizeof(princeX_)/sizeof(*princeX_)); 4fd800b3a8 2011-02-23 kinaba: int princeY_[] = {1,2,3}; 4fd800b3a8 2011-02-23 kinaba: vector <int> princeY(princeY_, princeY_+sizeof(princeY_)/sizeof(*princeY_)); 4fd800b3a8 2011-02-23 kinaba: int destinationX_[] = {0,0,0}; 4fd800b3a8 2011-02-23 kinaba: vector <int> destinationX(destinationX_, destinationX_+sizeof(destinationX_)/sizeof(*destinationX_)); 4fd800b3a8 2011-02-23 kinaba: int destinationY_[] = {0,2,4}; 4fd800b3a8 2011-02-23 kinaba: vector <int> destinationY(destinationY_, destinationY_+sizeof(destinationY_)/sizeof(*destinationY_)); 4fd800b3a8 2011-02-23 kinaba: double _ = 1.0; 4fd800b3a8 2011-02-23 kinaba: END 4fd800b3a8 2011-02-23 kinaba: CASE(2) 4fd800b3a8 2011-02-23 kinaba: int princeX_[] = {0,0,0}; 4fd800b3a8 2011-02-23 kinaba: vector <int> princeX(princeX_, princeX_+sizeof(princeX_)/sizeof(*princeX_)); 4fd800b3a8 2011-02-23 kinaba: int princeY_[] = {1,2,3}; 4fd800b3a8 2011-02-23 kinaba: vector <int> princeY(princeY_, princeY_+sizeof(princeY_)/sizeof(*princeY_)); 4fd800b3a8 2011-02-23 kinaba: int destinationX_[] = {0,0,0}; 4fd800b3a8 2011-02-23 kinaba: vector <int> destinationX(destinationX_, destinationX_+sizeof(destinationX_)/sizeof(*destinationX_)); 4fd800b3a8 2011-02-23 kinaba: int destinationY_[] = {4,2,0}; 4fd800b3a8 2011-02-23 kinaba: vector <int> destinationY(destinationY_, destinationY_+sizeof(destinationY_)/sizeof(*destinationY_)); 4fd800b3a8 2011-02-23 kinaba: double _ = 1.0; 4fd800b3a8 2011-02-23 kinaba: END 4fd800b3a8 2011-02-23 kinaba: CASE(3) 4fd800b3a8 2011-02-23 kinaba: int princeX_[] = {0,3,5}; 4fd800b3a8 2011-02-23 kinaba: vector <int> princeX(princeX_, princeX_+sizeof(princeX_)/sizeof(*princeX_)); 4fd800b3a8 2011-02-23 kinaba: int princeY_[] = {0,4,0}; 4fd800b3a8 2011-02-23 kinaba: vector <int> princeY(princeY_, princeY_+sizeof(princeY_)/sizeof(*princeY_)); 4fd800b3a8 2011-02-23 kinaba: int destinationX_[] = {3,5,0}; 4fd800b3a8 2011-02-23 kinaba: vector <int> destinationX(destinationX_, destinationX_+sizeof(destinationX_)/sizeof(*destinationX_)); 4fd800b3a8 2011-02-23 kinaba: int destinationY_[] = {4,0,0}; 4fd800b3a8 2011-02-23 kinaba: vector <int> destinationY(destinationY_, destinationY_+sizeof(destinationY_)/sizeof(*destinationY_)); 4fd800b3a8 2011-02-23 kinaba: double _ = 4.47213595499958; 4fd800b3a8 2011-02-23 kinaba: END 4fd800b3a8 2011-02-23 kinaba: CASE(4) 4fd800b3a8 2011-02-23 kinaba: int princeX_[] = {3629,6751,8655,5115,7809,6759,7133,1810,6102,2539,1777,242}; 4fd800b3a8 2011-02-23 kinaba: vector <int> princeX(princeX_, princeX_+sizeof(princeX_)/sizeof(*princeX_)); 4fd800b3a8 2011-02-23 kinaba: int princeY_[] = {5294,180,988,7780,1635,7904,845,7405,4800,2567,4795,2339}; 4fd800b3a8 2011-02-23 kinaba: vector <int> princeY(princeY_, princeY_+sizeof(princeY_)/sizeof(*princeY_)); 4fd800b3a8 2011-02-23 kinaba: int destinationX_[] = {8723,9275,6705,5875,7981,7666,1158,4135,17,2984,5086,3570}; 4fd800b3a8 2011-02-23 kinaba: vector <int> destinationX(destinationX_, destinationX_+sizeof(destinationX_)/sizeof(*destinationX_)); 4fd800b3a8 2011-02-23 kinaba: int destinationY_[] = {6166,53,5980,4499,412,9074,8190,847,650,9158,9116,4396}; 4fd800b3a8 2011-02-23 kinaba: vector <int> destinationY(destinationY_, destinationY_+sizeof(destinationY_)/sizeof(*destinationY_)); 4fd800b3a8 2011-02-23 kinaba: double _ = 2622.582696503582; 4fd800b3a8 2011-02-23 kinaba: END 4fd800b3a8 2011-02-23 kinaba: CASE(5) 4fd800b3a8 2011-02-23 kinaba: int princeX_[] = {0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9}; 4fd800b3a8 2011-02-23 kinaba: vector <int> princeX(princeX_, princeX_+sizeof(princeX_)/sizeof(*princeX_)); 4fd800b3a8 2011-02-23 kinaba: int princeY_[] = {0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9}; 4fd800b3a8 2011-02-23 kinaba: vector <int> princeY(princeY_, princeY_+sizeof(princeY_)/sizeof(*princeY_)); 4fd800b3a8 2011-02-23 kinaba: int destinationX_[] = {0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9}; 4fd800b3a8 2011-02-23 kinaba: vector <int> destinationX(destinationX_, destinationX_+sizeof(destinationX_)/sizeof(*destinationX_)); 4fd800b3a8 2011-02-23 kinaba: int destinationY_[] = {0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9}; 4fd800b3a8 2011-02-23 kinaba: vector <int> destinationY(destinationY_, destinationY_+sizeof(destinationY_)/sizeof(*destinationY_)); 4fd800b3a8 2011-02-23 kinaba: double _ = 0; 4fd800b3a8 2011-02-23 kinaba: END 4fd800b3a8 2011-02-23 kinaba: /* 4fd800b3a8 2011-02-23 kinaba: CASE(6) 4fd800b3a8 2011-02-23 kinaba: int princeX_[] = ; 4fd800b3a8 2011-02-23 kinaba: vector <int> princeX(princeX_, princeX_+sizeof(princeX_)/sizeof(*princeX_)); 4fd800b3a8 2011-02-23 kinaba: int princeY_[] = ; 4fd800b3a8 2011-02-23 kinaba: vector <int> princeY(princeY_, princeY_+sizeof(princeY_)/sizeof(*princeY_)); 4fd800b3a8 2011-02-23 kinaba: int destinationX_[] = ; 4fd800b3a8 2011-02-23 kinaba: vector <int> destinationX(destinationX_, destinationX_+sizeof(destinationX_)/sizeof(*destinationX_)); 4fd800b3a8 2011-02-23 kinaba: int destinationY_[] = ; 4fd800b3a8 2011-02-23 kinaba: vector <int> destinationY(destinationY_, destinationY_+sizeof(destinationY_)/sizeof(*destinationY_)); 4fd800b3a8 2011-02-23 kinaba: double _ = ; 4fd800b3a8 2011-02-23 kinaba: END 4fd800b3a8 2011-02-23 kinaba: */ 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: // END CUT HERE