712c7ed383 2013-03-06 kinaba: #include <iostream> 712c7ed383 2013-03-06 kinaba: #include <sstream> 712c7ed383 2013-03-06 kinaba: #include <iomanip> 712c7ed383 2013-03-06 kinaba: #include <vector> 712c7ed383 2013-03-06 kinaba: #include <string> 712c7ed383 2013-03-06 kinaba: #include <map> 712c7ed383 2013-03-06 kinaba: #include <set> 712c7ed383 2013-03-06 kinaba: #include <algorithm> 712c7ed383 2013-03-06 kinaba: #include <numeric> 712c7ed383 2013-03-06 kinaba: #include <iterator> 712c7ed383 2013-03-06 kinaba: #include <functional> 712c7ed383 2013-03-06 kinaba: #include <complex> 712c7ed383 2013-03-06 kinaba: #include <queue> 712c7ed383 2013-03-06 kinaba: #include <stack> 712c7ed383 2013-03-06 kinaba: #include <cmath> 712c7ed383 2013-03-06 kinaba: #include <cassert> 712c7ed383 2013-03-06 kinaba: using namespace std; 712c7ed383 2013-03-06 kinaba: typedef long long LL; 712c7ed383 2013-03-06 kinaba: typedef complex<double> CMP; 712c7ed383 2013-03-06 kinaba: 712c7ed383 2013-03-06 kinaba: class CandyOnDisk { public: 712c7ed383 2013-03-06 kinaba: string ableToAchieve(vector <int> x_, vector <int> y_, vector <int> r_, int sx, int sy, int tx, int ty) 712c7ed383 2013-03-06 kinaba: { 712c7ed383 2013-03-06 kinaba: if(sx==tx && sy==ty) 712c7ed383 2013-03-06 kinaba: return "YES"; 712c7ed383 2013-03-06 kinaba: 712c7ed383 2013-03-06 kinaba: vector<LL> x,y,r; 712c7ed383 2013-03-06 kinaba: { 712c7ed383 2013-03-06 kinaba: map<pair<LL,LL>,LL> xyr; 712c7ed383 2013-03-06 kinaba: for(int i=0; i<x_.size(); ++i) 712c7ed383 2013-03-06 kinaba: xyr[make_pair(x_[i],y_[i])] = max<LL>(xyr[make_pair(x_[i],y_[i])], r_[i]); 712c7ed383 2013-03-06 kinaba: for(map<pair<LL,LL>,LL>::iterator it=xyr.begin(); it!=xyr.end(); ++it) { 712c7ed383 2013-03-06 kinaba: x.push_back(it->first.first); 712c7ed383 2013-03-06 kinaba: y.push_back(it->first.second); 712c7ed383 2013-03-06 kinaba: r.push_back(it->second); 712c7ed383 2013-03-06 kinaba: } 712c7ed383 2013-03-06 kinaba: } 712c7ed383 2013-03-06 kinaba: 712c7ed383 2013-03-06 kinaba: const int N = x.size(); 712c7ed383 2013-03-06 kinaba: map<int, double> p; 712c7ed383 2013-03-06 kinaba: { 712c7ed383 2013-03-06 kinaba: for(int i=0; i<N; ++i) 712c7ed383 2013-03-06 kinaba: { 712c7ed383 2013-03-06 kinaba: LL dd = (sx-x[i])*(sx-x[i])+(sy-y[i])*(sy-y[i]); 712c7ed383 2013-03-06 kinaba: if( dd <= r[i]*r[i] ) 712c7ed383 2013-03-06 kinaba: { 712c7ed383 2013-03-06 kinaba: if( dd == (tx-x[i])*(tx-x[i])+(ty-y[i])*(ty-y[i]) ) 712c7ed383 2013-03-06 kinaba: return "YES"; 712c7ed383 2013-03-06 kinaba: bool ok = false; 712c7ed383 2013-03-06 kinaba: for(int k=0; k<N; ++k) if(k!=i) 712c7ed383 2013-03-06 kinaba: { 712c7ed383 2013-03-06 kinaba: LL d = (x[i]-x[k])*(x[i]-x[k]) + (y[i]-y[k])*(y[i]-y[k]); 712c7ed383 2013-03-06 kinaba: if( d <= (r[i]+r[k])*(r[i]+r[k]) ) 712c7ed383 2013-03-06 kinaba: ok = true; 712c7ed383 2013-03-06 kinaba: } 712c7ed383 2013-03-06 kinaba: if(ok) 712c7ed383 2013-03-06 kinaba: p[i] = sqrt((double)dd); 712c7ed383 2013-03-06 kinaba: } 712c7ed383 2013-03-06 kinaba: } 712c7ed383 2013-03-06 kinaba: } 712c7ed383 2013-03-06 kinaba: 712c7ed383 2013-03-06 kinaba: for(;;) 712c7ed383 2013-03-06 kinaba: { 712c7ed383 2013-03-06 kinaba: bool upd = false; 712c7ed383 2013-03-06 kinaba: map<int,double> p2 = p; 712c7ed383 2013-03-06 kinaba: for(map<int,double>::iterator it=p.begin(); it!=p.end(); ++it) 712c7ed383 2013-03-06 kinaba: { 712c7ed383 2013-03-06 kinaba: int i = it->first; 712c7ed383 2013-03-06 kinaba: double d = it->second; 712c7ed383 2013-03-06 kinaba: 712c7ed383 2013-03-06 kinaba: LL dd = (tx-x[i])*(tx-x[i])+(ty-y[i])*(ty-y[i]); 712c7ed383 2013-03-06 kinaba: if(d*d <= dd && dd <= r[i]*r[i]) 712c7ed383 2013-03-06 kinaba: return "YES"; 712c7ed383 2013-03-06 kinaba: 712c7ed383 2013-03-06 kinaba: for(int k=0; k<N; ++k) if(k!=i) 712c7ed383 2013-03-06 kinaba: { 712c7ed383 2013-03-06 kinaba: double z = abs(CMP(x[i],y[i])-CMP(x[k],y[k])); 712c7ed383 2013-03-06 kinaba: if(max(0.0, z-r[k]) <= d) { 712c7ed383 2013-03-06 kinaba: double dk = max(0.0, z-r[i]); 712c7ed383 2013-03-06 kinaba: if(!p2.count(k) || p2[k]>dk) { 712c7ed383 2013-03-06 kinaba: upd = true; 712c7ed383 2013-03-06 kinaba: p2[k] = dk; 712c7ed383 2013-03-06 kinaba: } 712c7ed383 2013-03-06 kinaba: } 712c7ed383 2013-03-06 kinaba: } 712c7ed383 2013-03-06 kinaba: } 712c7ed383 2013-03-06 kinaba: if(!upd) 712c7ed383 2013-03-06 kinaba: break; 712c7ed383 2013-03-06 kinaba: p.swap(p2); 712c7ed383 2013-03-06 kinaba: } 712c7ed383 2013-03-06 kinaba: 712c7ed383 2013-03-06 kinaba: return "NO"; 712c7ed383 2013-03-06 kinaba: } 712c7ed383 2013-03-06 kinaba: }; 712c7ed383 2013-03-06 kinaba: 712c7ed383 2013-03-06 kinaba: // BEGIN CUT HERE 712c7ed383 2013-03-06 kinaba: #include <ctime> 712c7ed383 2013-03-06 kinaba: double start_time; string timer() 712c7ed383 2013-03-06 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 712c7ed383 2013-03-06 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 712c7ed383 2013-03-06 kinaba: { os << "{ "; 712c7ed383 2013-03-06 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 712c7ed383 2013-03-06 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 712c7ed383 2013-03-06 kinaba: void verify_case(const string& Expected, const string& Received) { 712c7ed383 2013-03-06 kinaba: bool ok = (Expected == Received); 712c7ed383 2013-03-06 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 712c7ed383 2013-03-06 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 712c7ed383 2013-03-06 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 712c7ed383 2013-03-06 kinaba: #define END verify_case(_, CandyOnDisk().ableToAchieve(x, y, r, sx, sy, tx, ty));} 712c7ed383 2013-03-06 kinaba: int main(){ 712c7ed383 2013-03-06 kinaba: 712c7ed383 2013-03-06 kinaba: CASE(0) 712c7ed383 2013-03-06 kinaba: int x_[] = {0, 4}; 712c7ed383 2013-03-06 kinaba: vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 712c7ed383 2013-03-06 kinaba: int y_[] = {0, 0}; 712c7ed383 2013-03-06 kinaba: vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 712c7ed383 2013-03-06 kinaba: int r_[] = {3, 3}; 712c7ed383 2013-03-06 kinaba: vector <int> r(r_, r_+sizeof(r_)/sizeof(*r_)); 712c7ed383 2013-03-06 kinaba: int sx = -1; 712c7ed383 2013-03-06 kinaba: int sy = -2; 712c7ed383 2013-03-06 kinaba: int tx = 6; 712c7ed383 2013-03-06 kinaba: int ty = 1; 712c7ed383 2013-03-06 kinaba: string _ = "YES"; 712c7ed383 2013-03-06 kinaba: END 712c7ed383 2013-03-06 kinaba: CASE(1) 712c7ed383 2013-03-06 kinaba: int x_[] = {0, 3}; 712c7ed383 2013-03-06 kinaba: vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 712c7ed383 2013-03-06 kinaba: int y_[] = {0, 0}; 712c7ed383 2013-03-06 kinaba: vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 712c7ed383 2013-03-06 kinaba: int r_[] = {5, 3}; 712c7ed383 2013-03-06 kinaba: vector <int> r(r_, r_+sizeof(r_)/sizeof(*r_)); 712c7ed383 2013-03-06 kinaba: int sx = -4; 712c7ed383 2013-03-06 kinaba: int sy = 0; 712c7ed383 2013-03-06 kinaba: int tx = -2; 712c7ed383 2013-03-06 kinaba: int ty = 0; 712c7ed383 2013-03-06 kinaba: string _ = "YES"; 712c7ed383 2013-03-06 kinaba: END 712c7ed383 2013-03-06 kinaba: CASE(2) 712c7ed383 2013-03-06 kinaba: int x_[] = {0}; 712c7ed383 2013-03-06 kinaba: vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 712c7ed383 2013-03-06 kinaba: int y_[] = {0}; 712c7ed383 2013-03-06 kinaba: vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 712c7ed383 2013-03-06 kinaba: int r_[] = {1}; 712c7ed383 2013-03-06 kinaba: vector <int> r(r_, r_+sizeof(r_)/sizeof(*r_)); 712c7ed383 2013-03-06 kinaba: int sx = 0; 712c7ed383 2013-03-06 kinaba: int sy = 0; 712c7ed383 2013-03-06 kinaba: int tx = 571; 712c7ed383 2013-03-06 kinaba: int ty = 571; 712c7ed383 2013-03-06 kinaba: string _ = "NO"; 712c7ed383 2013-03-06 kinaba: END 712c7ed383 2013-03-06 kinaba: CASE(3) 712c7ed383 2013-03-06 kinaba: int x_[] = {0}; 712c7ed383 2013-03-06 kinaba: vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 712c7ed383 2013-03-06 kinaba: int y_[] = {0}; 712c7ed383 2013-03-06 kinaba: vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 712c7ed383 2013-03-06 kinaba: int r_[] = {1}; 712c7ed383 2013-03-06 kinaba: vector <int> r(r_, r_+sizeof(r_)/sizeof(*r_)); 712c7ed383 2013-03-06 kinaba: int sx = 571; 712c7ed383 2013-03-06 kinaba: int sy = 571; 712c7ed383 2013-03-06 kinaba: int tx = 571; 712c7ed383 2013-03-06 kinaba: int ty = 571; 712c7ed383 2013-03-06 kinaba: string _ = "YES"; 712c7ed383 2013-03-06 kinaba: END 712c7ed383 2013-03-06 kinaba: CASE(4) 712c7ed383 2013-03-06 kinaba: int x_[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}; 712c7ed383 2013-03-06 kinaba: vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 712c7ed383 2013-03-06 kinaba: int y_[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}; 712c7ed383 2013-03-06 kinaba: vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 712c7ed383 2013-03-06 kinaba: int r_[] = {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}; 712c7ed383 2013-03-06 kinaba: vector <int> r(r_, r_+sizeof(r_)/sizeof(*r_)); 712c7ed383 2013-03-06 kinaba: int sx = 2; 712c7ed383 2013-03-06 kinaba: int sy = 2; 712c7ed383 2013-03-06 kinaba: int tx = 19; 712c7ed383 2013-03-06 kinaba: int ty = 19; 712c7ed383 2013-03-06 kinaba: string _ = "YES"; 712c7ed383 2013-03-06 kinaba: END 712c7ed383 2013-03-06 kinaba: CASE(5) 712c7ed383 2013-03-06 kinaba: int x_[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}; 712c7ed383 2013-03-06 kinaba: vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 712c7ed383 2013-03-06 kinaba: int y_[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}; 712c7ed383 2013-03-06 kinaba: vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 712c7ed383 2013-03-06 kinaba: int r_[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; 712c7ed383 2013-03-06 kinaba: vector <int> r(r_, r_+sizeof(r_)/sizeof(*r_)); 712c7ed383 2013-03-06 kinaba: int sx = 2; 712c7ed383 2013-03-06 kinaba: int sy = 2; 712c7ed383 2013-03-06 kinaba: int tx = 19; 712c7ed383 2013-03-06 kinaba: int ty = 19; 712c7ed383 2013-03-06 kinaba: string _ = "NO"; 712c7ed383 2013-03-06 kinaba: END 712c7ed383 2013-03-06 kinaba: /* 712c7ed383 2013-03-06 kinaba: CASE(6) 712c7ed383 2013-03-06 kinaba: int x_[] = ; 712c7ed383 2013-03-06 kinaba: vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 712c7ed383 2013-03-06 kinaba: int y_[] = ; 712c7ed383 2013-03-06 kinaba: vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 712c7ed383 2013-03-06 kinaba: int r_[] = ; 712c7ed383 2013-03-06 kinaba: vector <int> r(r_, r_+sizeof(r_)/sizeof(*r_)); 712c7ed383 2013-03-06 kinaba: int sx = ; 712c7ed383 2013-03-06 kinaba: int sy = ; 712c7ed383 2013-03-06 kinaba: int tx = ; 712c7ed383 2013-03-06 kinaba: int ty = ; 712c7ed383 2013-03-06 kinaba: string _ = ; 712c7ed383 2013-03-06 kinaba: END 712c7ed383 2013-03-06 kinaba: CASE(7) 712c7ed383 2013-03-06 kinaba: int x_[] = ; 712c7ed383 2013-03-06 kinaba: vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 712c7ed383 2013-03-06 kinaba: int y_[] = ; 712c7ed383 2013-03-06 kinaba: vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 712c7ed383 2013-03-06 kinaba: int r_[] = ; 712c7ed383 2013-03-06 kinaba: vector <int> r(r_, r_+sizeof(r_)/sizeof(*r_)); 712c7ed383 2013-03-06 kinaba: int sx = ; 712c7ed383 2013-03-06 kinaba: int sy = ; 712c7ed383 2013-03-06 kinaba: int tx = ; 712c7ed383 2013-03-06 kinaba: int ty = ; 712c7ed383 2013-03-06 kinaba: string _ = ; 712c7ed383 2013-03-06 kinaba: END 712c7ed383 2013-03-06 kinaba: */ 712c7ed383 2013-03-06 kinaba: } 712c7ed383 2013-03-06 kinaba: // END CUT HERE