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 Aircraft { public: 4fd800b3a8 2011-02-23 kinaba: double f(const double p[], const double v[], double t) 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: return sqrt( (p[0]+t*v[0])*(p[0]+t*v[0]) + (p[1]+t*v[1])*(p[1]+t*v[1]) + (p[2]+t*v[2])*(p[2]+t*v[2]) ); 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: string nearMiss(vector <int> p1, vector <int> v1, vector <int> p2, vector <int> v2, int R) 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: const double p[] = {p1[0]-p2[0], p1[1]-p2[1], p1[2]-p2[2]}; 4fd800b3a8 2011-02-23 kinaba: const double v[] = {v1[0]-v2[0], v1[1]-v2[1], v1[2]-v2[2]}; 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: double x = 0.0; 4fd800b3a8 2011-02-23 kinaba: double w = 1e+10; 4fd800b3a8 2011-02-23 kinaba: for(int k=0; k<1000000; ++k) 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: double y = 2*x/3 + w/3; 4fd800b3a8 2011-02-23 kinaba: double z = x/3 + 2*w/3; 4fd800b3a8 2011-02-23 kinaba: double fx = f(p,v,x); 4fd800b3a8 2011-02-23 kinaba: double fy = f(p,v,y); 4fd800b3a8 2011-02-23 kinaba: double fz = f(p,v,z); 4fd800b3a8 2011-02-23 kinaba: double fw = f(p,v,w); 4fd800b3a8 2011-02-23 kinaba: if( fx < fy ) 4fd800b3a8 2011-02-23 kinaba: w = y; 4fd800b3a8 2011-02-23 kinaba: else if( fz > fw ) 4fd800b3a8 2011-02-23 kinaba: x = z; 4fd800b3a8 2011-02-23 kinaba: else if( fy < fz ) 4fd800b3a8 2011-02-23 kinaba: w = z; 4fd800b3a8 2011-02-23 kinaba: else 4fd800b3a8 2011-02-23 kinaba: x = y; 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: return f(p,v,x)-0.000001<=R ? "YES" : "NO"; 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 string& Expected, const string& Received) { 4fd800b3a8 2011-02-23 kinaba: bool ok = (Expected == Received); 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(_, Aircraft().nearMiss(p1, v1, p2, v2, R));} 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 p1_[] = {15,50,5}; 4fd800b3a8 2011-02-23 kinaba: vector <int> p1(p1_, p1_+sizeof(p1_)/sizeof(*p1_)); 4fd800b3a8 2011-02-23 kinaba: int v1_[] = {25,1,0}; 4fd800b3a8 2011-02-23 kinaba: vector <int> v1(v1_, v1_+sizeof(v1_)/sizeof(*v1_)); 4fd800b3a8 2011-02-23 kinaba: int p2_[] = {161,102,9}; 4fd800b3a8 2011-02-23 kinaba: vector <int> p2(p2_, p2_+sizeof(p2_)/sizeof(*p2_)); 4fd800b3a8 2011-02-23 kinaba: int v2_[] = {-10,-10,-1}; 4fd800b3a8 2011-02-23 kinaba: vector <int> v2(v2_, v2_+sizeof(v2_)/sizeof(*v2_)); 4fd800b3a8 2011-02-23 kinaba: int R = 10; 4fd800b3a8 2011-02-23 kinaba: string _ = "YES"; 4fd800b3a8 2011-02-23 kinaba: END 4fd800b3a8 2011-02-23 kinaba: CASE(1) 4fd800b3a8 2011-02-23 kinaba: int p1_[] = {0,0,0}; 4fd800b3a8 2011-02-23 kinaba: vector <int> p1(p1_, p1_+sizeof(p1_)/sizeof(*p1_)); 4fd800b3a8 2011-02-23 kinaba: int v1_[] = {2,2,0}; 4fd800b3a8 2011-02-23 kinaba: vector <int> v1(v1_, v1_+sizeof(v1_)/sizeof(*v1_)); 4fd800b3a8 2011-02-23 kinaba: int p2_[] = {9,0,5}; 4fd800b3a8 2011-02-23 kinaba: vector <int> p2(p2_, p2_+sizeof(p2_)/sizeof(*p2_)); 4fd800b3a8 2011-02-23 kinaba: int v2_[] = {-2,2,0}; 4fd800b3a8 2011-02-23 kinaba: vector <int> v2(v2_, v2_+sizeof(v2_)/sizeof(*v2_)); 4fd800b3a8 2011-02-23 kinaba: int R = 5; 4fd800b3a8 2011-02-23 kinaba: string _ = "YES"; 4fd800b3a8 2011-02-23 kinaba: END 4fd800b3a8 2011-02-23 kinaba: CASE(2) 4fd800b3a8 2011-02-23 kinaba: int p1_[] = {0,0,0}; 4fd800b3a8 2011-02-23 kinaba: vector <int> p1(p1_, p1_+sizeof(p1_)/sizeof(*p1_)); 4fd800b3a8 2011-02-23 kinaba: int v1_[] = {-2,2,0}; 4fd800b3a8 2011-02-23 kinaba: vector <int> v1(v1_, v1_+sizeof(v1_)/sizeof(*v1_)); 4fd800b3a8 2011-02-23 kinaba: int p2_[] = {9,0,5}; 4fd800b3a8 2011-02-23 kinaba: vector <int> p2(p2_, p2_+sizeof(p2_)/sizeof(*p2_)); 4fd800b3a8 2011-02-23 kinaba: int v2_[] = {2,2,0}; 4fd800b3a8 2011-02-23 kinaba: vector <int> v2(v2_, v2_+sizeof(v2_)/sizeof(*v2_)); 4fd800b3a8 2011-02-23 kinaba: int R = 5; 4fd800b3a8 2011-02-23 kinaba: string _ = "NO"; 4fd800b3a8 2011-02-23 kinaba: END 4fd800b3a8 2011-02-23 kinaba: CASE(3) 4fd800b3a8 2011-02-23 kinaba: int p1_[] = {-2838,-7940,-2936}; 4fd800b3a8 2011-02-23 kinaba: vector <int> p1(p1_, p1_+sizeof(p1_)/sizeof(*p1_)); 4fd800b3a8 2011-02-23 kinaba: int v1_[] = {1,1,-2}; 4fd800b3a8 2011-02-23 kinaba: vector <int> v1(v1_, v1_+sizeof(v1_)/sizeof(*v1_)); 4fd800b3a8 2011-02-23 kinaba: int p2_[] = {532,3850,9590}; 4fd800b3a8 2011-02-23 kinaba: vector <int> p2(p2_, p2_+sizeof(p2_)/sizeof(*p2_)); 4fd800b3a8 2011-02-23 kinaba: int v2_[] = {1,0,-3}; 4fd800b3a8 2011-02-23 kinaba: vector <int> v2(v2_, v2_+sizeof(v2_)/sizeof(*v2_)); 4fd800b3a8 2011-02-23 kinaba: int R = 3410; 4fd800b3a8 2011-02-23 kinaba: string _ = "YES"; 4fd800b3a8 2011-02-23 kinaba: END 4fd800b3a8 2011-02-23 kinaba: CASE(4) 4fd800b3a8 2011-02-23 kinaba: int p1_[] = {-8509,9560,345}; 4fd800b3a8 2011-02-23 kinaba: vector <int> p1(p1_, p1_+sizeof(p1_)/sizeof(*p1_)); 4fd800b3a8 2011-02-23 kinaba: int v1_[] = {-89,-33,62}; 4fd800b3a8 2011-02-23 kinaba: vector <int> v1(v1_, v1_+sizeof(v1_)/sizeof(*v1_)); 4fd800b3a8 2011-02-23 kinaba: int p2_[] = {-5185,-1417,2846}; 4fd800b3a8 2011-02-23 kinaba: vector <int> p2(p2_, p2_+sizeof(p2_)/sizeof(*p2_)); 4fd800b3a8 2011-02-23 kinaba: int v2_[] = {-58,24,26}; 4fd800b3a8 2011-02-23 kinaba: vector <int> v2(v2_, v2_+sizeof(v2_)/sizeof(*v2_)); 4fd800b3a8 2011-02-23 kinaba: int R = 8344; 4fd800b3a8 2011-02-23 kinaba: string _ = "YES"; 4fd800b3a8 2011-02-23 kinaba: END 4fd800b3a8 2011-02-23 kinaba: CASE(5) 4fd800b3a8 2011-02-23 kinaba: int p1_[] = {-7163,-371,-2459}; 4fd800b3a8 2011-02-23 kinaba: vector <int> p1(p1_, p1_+sizeof(p1_)/sizeof(*p1_)); 4fd800b3a8 2011-02-23 kinaba: int v1_[] = {-59,-41,-14}; 4fd800b3a8 2011-02-23 kinaba: vector <int> v1(v1_, v1_+sizeof(v1_)/sizeof(*v1_)); 4fd800b3a8 2011-02-23 kinaba: int p2_[] = {-2398,-426,-5487}; 4fd800b3a8 2011-02-23 kinaba: vector <int> p2(p2_, p2_+sizeof(p2_)/sizeof(*p2_)); 4fd800b3a8 2011-02-23 kinaba: int v2_[] = {-43,27,67}; 4fd800b3a8 2011-02-23 kinaba: vector <int> v2(v2_, v2_+sizeof(v2_)/sizeof(*v2_)); 4fd800b3a8 2011-02-23 kinaba: int R = 5410; 4fd800b3a8 2011-02-23 kinaba: string _ = "NO"; 4fd800b3a8 2011-02-23 kinaba: END 4fd800b3a8 2011-02-23 kinaba: CASE(6) 4fd800b3a8 2011-02-23 kinaba: int p1_[] = {1774,-4491,7810}; 4fd800b3a8 2011-02-23 kinaba: vector <int> p1(p1_, p1_+sizeof(p1_)/sizeof(*p1_)); 4fd800b3a8 2011-02-23 kinaba: int v1_[] = {-12,19,-24}; 4fd800b3a8 2011-02-23 kinaba: vector <int> v1(v1_, v1_+sizeof(v1_)/sizeof(*v1_)); 4fd800b3a8 2011-02-23 kinaba: int p2_[] = {2322,3793,9897}; 4fd800b3a8 2011-02-23 kinaba: vector <int> p2(p2_, p2_+sizeof(p2_)/sizeof(*p2_)); 4fd800b3a8 2011-02-23 kinaba: int v2_[] = {-12,19,-24}; 4fd800b3a8 2011-02-23 kinaba: vector <int> v2(v2_, v2_+sizeof(v2_)/sizeof(*v2_)); 4fd800b3a8 2011-02-23 kinaba: int R = 10000; 4fd800b3a8 2011-02-23 kinaba: string _ = "YES"; 4fd800b3a8 2011-02-23 kinaba: END 4fd800b3a8 2011-02-23 kinaba: CASE(7) 4fd800b3a8 2011-02-23 kinaba: int p1_[] = {3731,8537,5661}; 4fd800b3a8 2011-02-23 kinaba: vector <int> p1(p1_, p1_+sizeof(p1_)/sizeof(*p1_)); 4fd800b3a8 2011-02-23 kinaba: int v1_[] = {-70,71,32}; 4fd800b3a8 2011-02-23 kinaba: vector <int> v1(v1_, v1_+sizeof(v1_)/sizeof(*v1_)); 4fd800b3a8 2011-02-23 kinaba: int p2_[] = {8701,-1886,-5115}; 4fd800b3a8 2011-02-23 kinaba: vector <int> p2(p2_, p2_+sizeof(p2_)/sizeof(*p2_)); 4fd800b3a8 2011-02-23 kinaba: int v2_[] = {28,-13,7}; 4fd800b3a8 2011-02-23 kinaba: vector <int> v2(v2_, v2_+sizeof(v2_)/sizeof(*v2_)); 4fd800b3a8 2011-02-23 kinaba: int R = 9766; 4fd800b3a8 2011-02-23 kinaba: string _ = "NO"; 4fd800b3a8 2011-02-23 kinaba: END 4fd800b3a8 2011-02-23 kinaba: CASE(8) 4fd800b3a8 2011-02-23 kinaba: int p1_[] = {0,0,0}; 4fd800b3a8 2011-02-23 kinaba: vector <int> p1(p1_, p1_+sizeof(p1_)/sizeof(*p1_)); 4fd800b3a8 2011-02-23 kinaba: int v1_[] = {0,0,0}; 4fd800b3a8 2011-02-23 kinaba: vector <int> v1(v1_, v1_+sizeof(v1_)/sizeof(*v1_)); 4fd800b3a8 2011-02-23 kinaba: int p2_[] = {1,0,0}; 4fd800b3a8 2011-02-23 kinaba: vector <int> p2(p2_, p2_+sizeof(p2_)/sizeof(*p2_)); 4fd800b3a8 2011-02-23 kinaba: int v2_[] = {0,0,0}; 4fd800b3a8 2011-02-23 kinaba: vector <int> v2(v2_, v2_+sizeof(v2_)/sizeof(*v2_)); 4fd800b3a8 2011-02-23 kinaba: int R = 1; 4fd800b3a8 2011-02-23 kinaba: string _ = "YES"; 4fd800b3a8 2011-02-23 kinaba: END 4fd800b3a8 2011-02-23 kinaba: CASE(9) 4fd800b3a8 2011-02-23 kinaba: int p1_[] = {0,0,0}; 4fd800b3a8 2011-02-23 kinaba: vector <int> p1(p1_, p1_+sizeof(p1_)/sizeof(*p1_)); 4fd800b3a8 2011-02-23 kinaba: int v1_[] = {0,0,0}; 4fd800b3a8 2011-02-23 kinaba: vector <int> v1(v1_, v1_+sizeof(v1_)/sizeof(*v1_)); 4fd800b3a8 2011-02-23 kinaba: int p2_[] = {2,0,0}; 4fd800b3a8 2011-02-23 kinaba: vector <int> p2(p2_, p2_+sizeof(p2_)/sizeof(*p2_)); 4fd800b3a8 2011-02-23 kinaba: int v2_[] = {0,0,0}; 4fd800b3a8 2011-02-23 kinaba: vector <int> v2(v2_, v2_+sizeof(v2_)/sizeof(*v2_)); 4fd800b3a8 2011-02-23 kinaba: int R = 1; 4fd800b3a8 2011-02-23 kinaba: string _ = "NO"; 4fd800b3a8 2011-02-23 kinaba: END 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: // END CUT HERE