ADDED SRM/571-U/1A-U.cpp Index: SRM/571-U/1A-U.cpp ================================================================== --- SRM/571-U/1A-U.cpp +++ SRM/571-U/1A-U.cpp @@ -0,0 +1,126 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef long long LL; +typedef long double LD; +typedef complex CMP; + +class FoxAndMp3 { public: + set used; + vector playList(int n) + { + vector answer; + int v = 1; + while(answer.size() <= 50) + { + used.insert(v); + answer.push_back(to_s(v)+".mp3"); + int vv; + if(!next(v,n,&vv)) + break; + v=vv; + if(v==0) + break; + } + return answer; + } + + string to_s(int v) + { + stringstream ss; + ss << v; + return ss.str(); + } + + bool next(int v, int n, int* vv) + { + if(v*10<=n) { + *vv = v*10; + return true; + } + if(v+1 <= n && (v+1)%10!=0) { + *vv = v+1; + return true; + } + if(v+1 > n || (v+1)%10==0) { + *vv=v/10+1; + return !used.count(*vv); + } + return false; + } +}; + +// BEGIN CUT HERE +#include +double start_time; string timer() + { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } +template ostream& operator<<(ostream& os, const vector& v) + { os << "{ "; + for(typename vector::const_iterator it=v.begin(); it!=v.end(); ++it) + os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } +void verify_case(const vector & Expected, const vector & Received) { + bool ok = (Expected == Received); + if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; + cerr << "\to: " << Expected << endl << "\tx: " << Received << endl; } } +#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); +#define END verify_case(_, FoxAndMp3().playList(n));} +int main(){ + +CASE(0) + int n = 3; + string __[] = {"1.mp3", "2.mp3", "3.mp3" }; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +CASE(1) + int n = 10; + string __[] = {"1.mp3", "10.mp3", "2.mp3", "3.mp3", "4.mp3", "5.mp3", "6.mp3", "7.mp3", "8.mp3", "9.mp3" }; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +CASE(2) + int n = 16; + string __[] = {"1.mp3", "10.mp3", "11.mp3", "12.mp3", "13.mp3", "14.mp3", "15.mp3", "16.mp3", "2.mp3", "3.mp3", "4.mp3", "5.mp3", "6.mp3", "7.mp3", "8.mp3", "9.mp3" }; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +CASE(3) + int n = 32; + string __[] = {"1.mp3", "10.mp3", "11.mp3", "12.mp3", "13.mp3", "14.mp3", "15.mp3", "16.mp3", "17.mp3", "18.mp3", "19.mp3", "2.mp3", "20.mp3", "21.mp3", "22.mp3", "23.mp3", "24.mp3", "25.mp3", "26.mp3", "27.mp3", "28.mp3", "29.mp3", "3.mp3", "30.mp3", "31.mp3", "32.mp3", "4.mp3", "5.mp3", "6.mp3", "7.mp3", "8.mp3", "9.mp3" }; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +CASE(4) + int n = 100000009; + string __[] = {"1.mp3", "10.mp3", "100.mp3", "1000.mp3", "10000.mp3", "100000.mp3", "1000000.mp3", "10000000.mp3", "100000000.mp3", "100000001.mp3", "100000002.mp3", "100000003.mp3", "100000004.mp3", "100000005.mp3", "100000006.mp3", "100000007.mp3", "100000008.mp3", "100000009.mp3", "10000001.mp3", "10000002.mp3", "10000003.mp3", "10000004.mp3", "10000005.mp3", "10000006.mp3", "10000007.mp3", "10000008.mp3", "10000009.mp3", "1000001.mp3", "10000010.mp3", "10000011.mp3", "10000012.mp3", "10000013.mp3", "10000014.mp3", "10000015.mp3", "10000016.mp3", "10000017.mp3", "10000018.mp3", "10000019.mp3", "1000002.mp3", "10000020.mp3", "10000021.mp3", "10000022.mp3", "10000023.mp3", "10000024.mp3", "10000025.mp3", "10000026.mp3", "10000027.mp3", "10000028.mp3", "10000029.mp3", "1000003.mp3" }; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +CASE(5) + int n = 1; + string __[] = {"1.mp3" }; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +/* +CASE(6) + int n = ; + string __[] = ; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +CASE(7) + int n = ; + string __[] = ; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +*/ +} +// END CUT HERE ADDED SRM/571-U/1C-U.cpp Index: SRM/571-U/1C-U.cpp ================================================================== --- SRM/571-U/1C-U.cpp +++ SRM/571-U/1C-U.cpp @@ -0,0 +1,219 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef long long LL; +typedef complex CMP; + +class CandyOnDisk { public: + string ableToAchieve(vector x_, vector y_, vector r_, int sx, int sy, int tx, int ty) + { + if(sx==tx && sy==ty) + return "YES"; + + vector x,y,r; + { + map,LL> xyr; + for(int i=0; i(xyr[make_pair(x_[i],y_[i])], r_[i]); + for(map,LL>::iterator it=xyr.begin(); it!=xyr.end(); ++it) { + x.push_back(it->first.first); + y.push_back(it->first.second); + r.push_back(it->second); + } + } + + const int N = x.size(); + map p; + { + for(int i=0; i p2 = p; + for(map::iterator it=p.begin(); it!=p.end(); ++it) + { + int i = it->first; + double d = it->second; + + LL dd = (tx-x[i])*(tx-x[i])+(ty-y[i])*(ty-y[i]); + if(d*d <= dd && dd <= r[i]*r[i]) + return "YES"; + + for(int k=0; kdk) { + upd = true; + p2[k] = dk; + } + } + } + } + if(!upd) + break; + p.swap(p2); + } + + return "NO"; + } +}; + +// BEGIN CUT HERE +#include +double start_time; string timer() + { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } +template ostream& operator<<(ostream& os, const vector& v) + { os << "{ "; + for(typename vector::const_iterator it=v.begin(); it!=v.end(); ++it) + os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } +void verify_case(const string& Expected, const string& Received) { + bool ok = (Expected == Received); + if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; + cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } +#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); +#define END verify_case(_, CandyOnDisk().ableToAchieve(x, y, r, sx, sy, tx, ty));} +int main(){ + +CASE(0) + int x_[] = {0, 4}; + vector x(x_, x_+sizeof(x_)/sizeof(*x_)); + int y_[] = {0, 0}; + vector y(y_, y_+sizeof(y_)/sizeof(*y_)); + int r_[] = {3, 3}; + vector r(r_, r_+sizeof(r_)/sizeof(*r_)); + int sx = -1; + int sy = -2; + int tx = 6; + int ty = 1; + string _ = "YES"; +END +CASE(1) + int x_[] = {0, 3}; + vector x(x_, x_+sizeof(x_)/sizeof(*x_)); + int y_[] = {0, 0}; + vector y(y_, y_+sizeof(y_)/sizeof(*y_)); + int r_[] = {5, 3}; + vector r(r_, r_+sizeof(r_)/sizeof(*r_)); + int sx = -4; + int sy = 0; + int tx = -2; + int ty = 0; + string _ = "YES"; +END +CASE(2) + int x_[] = {0}; + vector x(x_, x_+sizeof(x_)/sizeof(*x_)); + int y_[] = {0}; + vector y(y_, y_+sizeof(y_)/sizeof(*y_)); + int r_[] = {1}; + vector r(r_, r_+sizeof(r_)/sizeof(*r_)); + int sx = 0; + int sy = 0; + int tx = 571; + int ty = 571; + string _ = "NO"; +END +CASE(3) + int x_[] = {0}; + vector x(x_, x_+sizeof(x_)/sizeof(*x_)); + int y_[] = {0}; + vector y(y_, y_+sizeof(y_)/sizeof(*y_)); + int r_[] = {1}; + vector r(r_, r_+sizeof(r_)/sizeof(*r_)); + int sx = 571; + int sy = 571; + int tx = 571; + int ty = 571; + string _ = "YES"; +END +CASE(4) + int x_[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}; + vector x(x_, x_+sizeof(x_)/sizeof(*x_)); + int y_[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}; + vector y(y_, y_+sizeof(y_)/sizeof(*y_)); + int r_[] = {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}; + vector r(r_, r_+sizeof(r_)/sizeof(*r_)); + int sx = 2; + int sy = 2; + int tx = 19; + int ty = 19; + string _ = "YES"; +END +CASE(5) + int x_[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}; + vector x(x_, x_+sizeof(x_)/sizeof(*x_)); + int y_[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}; + vector y(y_, y_+sizeof(y_)/sizeof(*y_)); + int r_[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; + vector r(r_, r_+sizeof(r_)/sizeof(*r_)); + int sx = 2; + int sy = 2; + int tx = 19; + int ty = 19; + string _ = "NO"; +END +/* +CASE(6) + int x_[] = ; + vector x(x_, x_+sizeof(x_)/sizeof(*x_)); + int y_[] = ; + vector y(y_, y_+sizeof(y_)/sizeof(*y_)); + int r_[] = ; + vector r(r_, r_+sizeof(r_)/sizeof(*r_)); + int sx = ; + int sy = ; + int tx = ; + int ty = ; + string _ = ; +END +CASE(7) + int x_[] = ; + vector x(x_, x_+sizeof(x_)/sizeof(*x_)); + int y_[] = ; + vector y(y_, y_+sizeof(y_)/sizeof(*y_)); + int r_[] = ; + vector r(r_, r_+sizeof(r_)/sizeof(*r_)); + int sx = ; + int sy = ; + int tx = ; + int ty = ; + string _ = ; +END +*/ +} +// END CUT HERE