5aef274bd6 2011-11-12 kinaba: #include <iostream> 5aef274bd6 2011-11-12 kinaba: #include <sstream> 5aef274bd6 2011-11-12 kinaba: #include <iomanip> 5aef274bd6 2011-11-12 kinaba: #include <vector> 5aef274bd6 2011-11-12 kinaba: #include <string> 5aef274bd6 2011-11-12 kinaba: #include <map> 5aef274bd6 2011-11-12 kinaba: #include <set> 5aef274bd6 2011-11-12 kinaba: #include <algorithm> 5aef274bd6 2011-11-12 kinaba: #include <numeric> 5aef274bd6 2011-11-12 kinaba: #include <iterator> 5aef274bd6 2011-11-12 kinaba: #include <functional> 5aef274bd6 2011-11-12 kinaba: #include <complex> 5aef274bd6 2011-11-12 kinaba: #include <queue> 5aef274bd6 2011-11-12 kinaba: #include <stack> 5aef274bd6 2011-11-12 kinaba: #include <cmath> 5aef274bd6 2011-11-12 kinaba: #include <cassert> 5aef274bd6 2011-11-12 kinaba: #include <cstring> 5aef274bd6 2011-11-12 kinaba: using namespace std; 5aef274bd6 2011-11-12 kinaba: typedef long long LL; 5aef274bd6 2011-11-12 kinaba: typedef complex<double> CMP; 5aef274bd6 2011-11-12 kinaba: 5aef274bd6 2011-11-12 kinaba: class CorrectMultiplicationTwo { public: 5aef274bd6 2011-11-12 kinaba: int getMinimum(int a, int b, int c) 5aef274bd6 2011-11-12 kinaba: { 5aef274bd6 2011-11-12 kinaba: LL score = 1LL<<62; 5aef274bd6 2011-11-12 kinaba: if(a>b) swap(a,b); 5aef274bd6 2011-11-12 kinaba: int Amax = int(sqrt((double)c))+999; 5aef274bd6 2011-11-12 kinaba: for (int A = 1; A <= Amax; A++) 5aef274bd6 2011-11-12 kinaba: { 5aef274bd6 2011-11-12 kinaba: for (int B = c/A-10; B <= c/A+10; B++) 5aef274bd6 2011-11-12 kinaba: { 5aef274bd6 2011-11-12 kinaba: if( B > 0 ) 5aef274bd6 2011-11-12 kinaba: score = min(score, abs(A-a)+abs(B-b)+abs(LL(A)*B-c)); 5aef274bd6 2011-11-12 kinaba: } 5aef274bd6 2011-11-12 kinaba: } 5aef274bd6 2011-11-12 kinaba: return score; 5aef274bd6 2011-11-12 kinaba: } 5aef274bd6 2011-11-12 kinaba: }; 5aef274bd6 2011-11-12 kinaba: 5aef274bd6 2011-11-12 kinaba: // BEGIN CUT HERE 5aef274bd6 2011-11-12 kinaba: #include <ctime> 5aef274bd6 2011-11-12 kinaba: double start_time; string timer() 5aef274bd6 2011-11-12 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 5aef274bd6 2011-11-12 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 5aef274bd6 2011-11-12 kinaba: { os << "{ "; 5aef274bd6 2011-11-12 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 5aef274bd6 2011-11-12 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 5aef274bd6 2011-11-12 kinaba: void verify_case(const int& Expected, const int& Received) { 5aef274bd6 2011-11-12 kinaba: bool ok = (Expected == Received); 5aef274bd6 2011-11-12 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 5aef274bd6 2011-11-12 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 5aef274bd6 2011-11-12 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 5aef274bd6 2011-11-12 kinaba: #define END verify_case(_, CorrectMultiplicationTwo().getMinimum(a, b, c));} 5aef274bd6 2011-11-12 kinaba: int main(){ 5aef274bd6 2011-11-12 kinaba: 5aef274bd6 2011-11-12 kinaba: CASE(0) 5aef274bd6 2011-11-12 kinaba: int a = 19; 5aef274bd6 2011-11-12 kinaba: int b = 28; 5aef274bd6 2011-11-12 kinaba: int c = 522; 5aef274bd6 2011-11-12 kinaba: int _ = 2; 5aef274bd6 2011-11-12 kinaba: END 5aef274bd6 2011-11-12 kinaba: CASE(1) 5aef274bd6 2011-11-12 kinaba: int a = 10; 5aef274bd6 2011-11-12 kinaba: int b = 30; 5aef274bd6 2011-11-12 kinaba: int c = 500; 5aef274bd6 2011-11-12 kinaba: int _ = 11; 5aef274bd6 2011-11-12 kinaba: END 5aef274bd6 2011-11-12 kinaba: CASE(2) 5aef274bd6 2011-11-12 kinaba: int a = 111; 5aef274bd6 2011-11-12 kinaba: int b = 111; 5aef274bd6 2011-11-12 kinaba: int c = 12321; 5aef274bd6 2011-11-12 kinaba: int _ = 0; 5aef274bd6 2011-11-12 kinaba: END 5aef274bd6 2011-11-12 kinaba: CASE(3) 5aef274bd6 2011-11-12 kinaba: int a = 1000; 5aef274bd6 2011-11-12 kinaba: int b = 100; 5aef274bd6 2011-11-12 kinaba: int c = 10; 5aef274bd6 2011-11-12 kinaba: int _ = 1089; 5aef274bd6 2011-11-12 kinaba: END 5aef274bd6 2011-11-12 kinaba: CASE(4) 5aef274bd6 2011-11-12 kinaba: int a = 399; 5aef274bd6 2011-11-12 kinaba: int b = 522; 5aef274bd6 2011-11-12 kinaba: int c = 199999; 5aef274bd6 2011-11-12 kinaba: int _ = 24; 5aef274bd6 2011-11-12 kinaba: END 5aef274bd6 2011-11-12 kinaba: /* 5aef274bd6 2011-11-12 kinaba: CASE(5) 5aef274bd6 2011-11-12 kinaba: int a = ; 5aef274bd6 2011-11-12 kinaba: int b = ; 5aef274bd6 2011-11-12 kinaba: int c = ; 5aef274bd6 2011-11-12 kinaba: int _ = ; 5aef274bd6 2011-11-12 kinaba: END 5aef274bd6 2011-11-12 kinaba: CASE(6) 5aef274bd6 2011-11-12 kinaba: int a = ; 5aef274bd6 2011-11-12 kinaba: int b = ; 5aef274bd6 2011-11-12 kinaba: int c = ; 5aef274bd6 2011-11-12 kinaba: int _ = ; 5aef274bd6 2011-11-12 kinaba: END 5aef274bd6 2011-11-12 kinaba: */ 5aef274bd6 2011-11-12 kinaba: } 5aef274bd6 2011-11-12 kinaba: // END CUT HERE