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 long double LD; 712c7ed383 2013-03-06 kinaba: typedef complex<LD> CMP; 712c7ed383 2013-03-06 kinaba: 712c7ed383 2013-03-06 kinaba: class FoxAndMp3 { public: 712c7ed383 2013-03-06 kinaba: set<int> used; 712c7ed383 2013-03-06 kinaba: vector <string> playList(int n) 712c7ed383 2013-03-06 kinaba: { 712c7ed383 2013-03-06 kinaba: vector<string> answer; 712c7ed383 2013-03-06 kinaba: int v = 1; 712c7ed383 2013-03-06 kinaba: while(answer.size() <= 50) 712c7ed383 2013-03-06 kinaba: { 712c7ed383 2013-03-06 kinaba: used.insert(v); 712c7ed383 2013-03-06 kinaba: answer.push_back(to_s(v)+".mp3"); 712c7ed383 2013-03-06 kinaba: int vv; 712c7ed383 2013-03-06 kinaba: if(!next(v,n,&vv)) 712c7ed383 2013-03-06 kinaba: break; 712c7ed383 2013-03-06 kinaba: v=vv; 712c7ed383 2013-03-06 kinaba: if(v==0) 712c7ed383 2013-03-06 kinaba: break; 712c7ed383 2013-03-06 kinaba: } 712c7ed383 2013-03-06 kinaba: return answer; 712c7ed383 2013-03-06 kinaba: } 712c7ed383 2013-03-06 kinaba: 712c7ed383 2013-03-06 kinaba: string to_s(int v) 712c7ed383 2013-03-06 kinaba: { 712c7ed383 2013-03-06 kinaba: stringstream ss; 712c7ed383 2013-03-06 kinaba: ss << v; 712c7ed383 2013-03-06 kinaba: return ss.str(); 712c7ed383 2013-03-06 kinaba: } 712c7ed383 2013-03-06 kinaba: 712c7ed383 2013-03-06 kinaba: bool next(int v, int n, int* vv) 712c7ed383 2013-03-06 kinaba: { 712c7ed383 2013-03-06 kinaba: if(v*10<=n) { 712c7ed383 2013-03-06 kinaba: *vv = v*10; 712c7ed383 2013-03-06 kinaba: return true; 712c7ed383 2013-03-06 kinaba: } 712c7ed383 2013-03-06 kinaba: if(v+1 <= n && (v+1)%10!=0) { 712c7ed383 2013-03-06 kinaba: *vv = v+1; 712c7ed383 2013-03-06 kinaba: return true; 712c7ed383 2013-03-06 kinaba: } 712c7ed383 2013-03-06 kinaba: if(v+1 > n || (v+1)%10==0) { 712c7ed383 2013-03-06 kinaba: *vv=v/10+1; 712c7ed383 2013-03-06 kinaba: return !used.count(*vv); 712c7ed383 2013-03-06 kinaba: } 712c7ed383 2013-03-06 kinaba: return false; 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 vector <string>& Expected, const vector <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(_, FoxAndMp3().playList(n));} 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 n = 3; 712c7ed383 2013-03-06 kinaba: string __[] = {"1.mp3", "2.mp3", "3.mp3" }; 712c7ed383 2013-03-06 kinaba: vector <string> _(__, __+sizeof(__)/sizeof(*__)); 712c7ed383 2013-03-06 kinaba: END 712c7ed383 2013-03-06 kinaba: CASE(1) 712c7ed383 2013-03-06 kinaba: int n = 10; 712c7ed383 2013-03-06 kinaba: string __[] = {"1.mp3", "10.mp3", "2.mp3", "3.mp3", "4.mp3", "5.mp3", "6.mp3", "7.mp3", "8.mp3", "9.mp3" }; 712c7ed383 2013-03-06 kinaba: vector <string> _(__, __+sizeof(__)/sizeof(*__)); 712c7ed383 2013-03-06 kinaba: END 712c7ed383 2013-03-06 kinaba: CASE(2) 712c7ed383 2013-03-06 kinaba: int n = 16; 712c7ed383 2013-03-06 kinaba: 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" }; 712c7ed383 2013-03-06 kinaba: vector <string> _(__, __+sizeof(__)/sizeof(*__)); 712c7ed383 2013-03-06 kinaba: END 712c7ed383 2013-03-06 kinaba: CASE(3) 712c7ed383 2013-03-06 kinaba: int n = 32; 712c7ed383 2013-03-06 kinaba: 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" }; 712c7ed383 2013-03-06 kinaba: vector <string> _(__, __+sizeof(__)/sizeof(*__)); 712c7ed383 2013-03-06 kinaba: END 712c7ed383 2013-03-06 kinaba: CASE(4) 712c7ed383 2013-03-06 kinaba: int n = 100000009; 712c7ed383 2013-03-06 kinaba: 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" }; 712c7ed383 2013-03-06 kinaba: vector <string> _(__, __+sizeof(__)/sizeof(*__)); 712c7ed383 2013-03-06 kinaba: END 712c7ed383 2013-03-06 kinaba: CASE(5) 712c7ed383 2013-03-06 kinaba: int n = 1; 712c7ed383 2013-03-06 kinaba: string __[] = {"1.mp3" }; 712c7ed383 2013-03-06 kinaba: vector <string> _(__, __+sizeof(__)/sizeof(*__)); 712c7ed383 2013-03-06 kinaba: END 712c7ed383 2013-03-06 kinaba: /* 712c7ed383 2013-03-06 kinaba: CASE(6) 712c7ed383 2013-03-06 kinaba: int n = ; 712c7ed383 2013-03-06 kinaba: string __[] = ; 712c7ed383 2013-03-06 kinaba: vector <string> _(__, __+sizeof(__)/sizeof(*__)); 712c7ed383 2013-03-06 kinaba: END 712c7ed383 2013-03-06 kinaba: CASE(7) 712c7ed383 2013-03-06 kinaba: int n = ; 712c7ed383 2013-03-06 kinaba: string __[] = ; 712c7ed383 2013-03-06 kinaba: vector <string> _(__, __+sizeof(__)/sizeof(*__)); 712c7ed383 2013-03-06 kinaba: END 712c7ed383 2013-03-06 kinaba: */ 712c7ed383 2013-03-06 kinaba: } 712c7ed383 2013-03-06 kinaba: // END CUT HERE