ADDED SRM/TCO20-2B-U/1A.cpp Index: SRM/TCO20-2B-U/1A.cpp ================================================================== --- SRM/TCO20-2B-U/1A.cpp +++ SRM/TCO20-2B-U/1A.cpp @@ -0,0 +1,125 @@ +#include +#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 FixedNumberOfDigits { public: + long long sum(int start, int step, long long numberOfDigits) + { + return solve(start, step, numberOfDigits); + } + + LL solve(LL s, LL inc, LL nd) { + LL next = 10; + int w = 1; + while (next <= s) { + next *= 10; + w += 1; + } + next = (next - s + inc - 1) / inc * inc + s; + LL k = (next - s) / inc; + if (k * w >= nd) { + LL q = nd / w; + LL r = nd % w; + if (r == 0) q -= 1, r += w; + + stringstream ss; + ss << (s + inc*q); + stringstream ss2; + ss2 << ss.str().substr(0, int(r)); + LL ans; + ss2 >> ans; + return ans; + } + return solve(next, inc, nd - k*w); + } +}; + +// 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 long long& Expected, const long long& 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(_, FixedNumberOfDigits().sum(start, step, numberOfDigits));} +int main(){ + +CASE(0) + int start = 47; + int step = 10; + long long numberOfDigits = 7LL; + long long _ = 7LL; +END +CASE(1) + int start = 98; + int step = 1; + long long numberOfDigits = 10LL; + long long _ = 101LL; +END +CASE(2) + int start = 0; + int step = 1; + long long numberOfDigits = 7LL; + long long _ = 6LL; +END +CASE(3) + int start = 123456789; + int step = 10; + long long numberOfDigits = 5LL; + long long _ = 12345LL; +END +CASE(4) + int start = 123456789; + int step = 10; + long long numberOfDigits = 17LL; + long long _ = 12345679LL; +END +CASE(5) + int start = 0; + int step = 1; + long long numberOfDigits = 15LL; + long long _ = 1LL; +END +CASE(6) +int start = 314; +int step = 11; +long long numberOfDigits = 9LL; +long long _ = 336LL; +END +CASE(6) +int start = 314; +int step = 11; +long long numberOfDigits = 192LL; +long long _ = 100LL; +END +CASE(6) +int start = 1; +int step = 612; +long long numberOfDigits = 10LL; +long long _ = 18LL; +END +} +// END CUT HERE ADDED SRM/TCO20-2B-U/1B-U.cpp Index: SRM/TCO20-2B-U/1B-U.cpp ================================================================== --- SRM/TCO20-2B-U/1B-U.cpp +++ SRM/TCO20-2B-U/1B-U.cpp @@ -0,0 +1,165 @@ +#include +#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 RoomPairs { public: + vector fix(vector s) { + for (size_t y = 1; y < s.size(); y += 2) + s[y][0] = s[y][s[y].size() - 1] = '|'; + for (size_t x = 1; x < s[0].size(); x += 2) + s[0][x] = s[s.size()-1][x] = '-'; + + for (size_t y = 0; y construct(int R, int C, int N) + { + return fix(solve(R, C, N)); + } + + vector solve(int R, int C, int N) + { + vector ans(R * 2 + 1, string(C * 2 + 1, ' ')); + if (N < C) { + for (int r=1; r < ans.size(); r+=2) { + for (int c = 0; c < N; ++c) + ans[r][c*2+2] = '|'; + } + return ans; + } + + for (int r = 2; r <= R; ++r) + if((r-1)*C+r*(C-1) >= N) + { + int cnt = (r - 2)*C + (r - 1)*(C - 1); + + vector h(C-1, true); + vector v(C, false); + for(; cnt= 0; --r) + if (v[r] == false) + break; + if (r > 1) { + v[r] = true; + h[0] = false; + } + else { + //.. + } + } + } + + for (int x = 0; x < h.size(); ++x) { + for (int y = 0; y < R; ++y) + if(y +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 << "{ \n"; + for(typename vector::const_iterator it=v.begin(); it!=v.end(); ++it) + os << '\"' << *it << '\"' << (it+1==v.end() ? "" : "\n"); 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(_, RoomPairs().construct(R, C, N));} +int main(){ + +CASE(0) + int R = 2; + int C = 4; + int N = 1; + string __[] = {"+-+-+-+-+", "| | | |", "+ + +-+ +", "| | |", "+-+-+-+-+" }; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +CASE(1) + int R = 3; + int C = 3; + int N = 4; + string __[] = {"+-+-+-+", "| | | |", "+-+ +-+", "| |", "+-+ +-+", "| | | |", "+-+-+-+" }; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +CASE(2) + int R = 3; + int C = 4; + int N = 3; + string __[] = {"+-+-+-+-+", "| |", "+ +-+-+ +", "| | | | |", "+ +-+-+ +", "| |", "+-+-+-+-+" }; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +CASE(3) + int R = 4; + int C = 5; + int N = 31; + string __[] = {"+-+-+-+-+-+", "| | | | | |", "+-+-+-+-+-+", "| | | | | |", "+-+-+-+-+-+", "| | | | | |", "+-+-+-+-+-+", "| | | | | |", "+-+-+-+-+-+" }; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +CASE(4) + int R = 1; + int C = 10; + int N = 4; + string __[] = { "!!" }; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +/* +CASE(5) + int R = ; + int C = ; + int N = ; + string __[] = { "!!" }; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +*/ +} +// END CUT HERE