ADDED SRM/522-U/2A.cpp Index: SRM/522-U/2A.cpp ================================================================== --- SRM/522-U/2A.cpp +++ SRM/522-U/2A.cpp @@ -0,0 +1,95 @@ +#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 PointErasingTwo { public: + int getMaximum(vector y) + { + int ans = 0; + for(int i=0; i +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 int& Expected, const int& 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(_, PointErasingTwo().getMaximum(y));} +int main(){ + +CASE(0) + int y_[] = { 1, 2, 1, 1, 0, 4, 3 }; + vector y(y_, y_+sizeof(y_)/sizeof(*y_)); + int _ = 2; +END +CASE(1) + int y_[] = { 0, 1 }; + vector y(y_, y_+sizeof(y_)/sizeof(*y_)); + int _ = 0; +END +CASE(2) + int y_[] = { 0, 1, 2, 3, 4 }; + vector y(y_, y_+sizeof(y_)/sizeof(*y_)); + int _ = 3; +END +CASE(3) + int y_[] = { 10, 19, 10, 19 }; + vector y(y_, y_+sizeof(y_)/sizeof(*y_)); + int _ = 0; +END +CASE(4) + int y_[] = { 0, 23, 49, 50, 32, 0, 18, 50, 0, 28, 50, 27, 49, 0 }; + vector y(y_, y_+sizeof(y_)/sizeof(*y_)); + int _ = 5; +END +/* +CASE(5) + int y_[] = ; + vector y(y_, y_+sizeof(y_)/sizeof(*y_)); + int _ = ; +END +CASE(6) + int y_[] = ; + vector y(y_, y_+sizeof(y_)/sizeof(*y_)); + int _ = ; +END +*/ +} +// END CUT HERE ADDED SRM/522-U/2C.cpp Index: SRM/522-U/2C.cpp ================================================================== --- SRM/522-U/2C.cpp +++ SRM/522-U/2C.cpp @@ -0,0 +1,101 @@ +#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 CorrectMultiplicationTwo { public: + int getMinimum(int a, int b, int c) + { + LL score = 1LL<<62; + if(a>b) swap(a,b); + int Amax = int(sqrt((double)c))+999; + for (int A = 1; A <= Amax; A++) + { + for (int B = c/A-10; B <= c/A+10; B++) + { + if( B > 0 ) + score = min(score, abs(A-a)+abs(B-b)+abs(LL(A)*B-c)); + } + } + return score; + } +}; + +// 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 int& Expected, const int& 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(_, CorrectMultiplicationTwo().getMinimum(a, b, c));} +int main(){ + +CASE(0) + int a = 19; + int b = 28; + int c = 522; + int _ = 2; +END +CASE(1) + int a = 10; + int b = 30; + int c = 500; + int _ = 11; +END +CASE(2) + int a = 111; + int b = 111; + int c = 12321; + int _ = 0; +END +CASE(3) + int a = 1000; + int b = 100; + int c = 10; + int _ = 1089; +END +CASE(4) + int a = 399; + int b = 522; + int c = 199999; + int _ = 24; +END +/* +CASE(5) + int a = ; + int b = ; + int c = ; + int _ = ; +END +CASE(6) + int a = ; + int b = ; + int c = ; + int _ = ; +END +*/ +} +// END CUT HERE