Check-in [5aef274bd6]
Not logged in
Overview
SHA1 Hash:5aef274bd61de6dc865b5dc0933505e867d30928
Date: 2011-11-12 16:24:48
User: kinaba
Comment:522-2
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | manifest
Tags And Properties
Changes

Added SRM/522-U/2A.cpp version [0b730a19c7ddccdb]

1 +#include <iostream> 2 +#include <sstream> 3 +#include <iomanip> 4 +#include <vector> 5 +#include <string> 6 +#include <map> 7 +#include <set> 8 +#include <algorithm> 9 +#include <numeric> 10 +#include <iterator> 11 +#include <functional> 12 +#include <complex> 13 +#include <queue> 14 +#include <stack> 15 +#include <cmath> 16 +#include <cassert> 17 +#include <cstring> 18 +using namespace std; 19 +typedef long long LL; 20 +typedef complex<double> CMP; 21 + 22 +class PointErasingTwo { public: 23 + int getMaximum(vector <int> y) 24 + { 25 + int ans = 0; 26 + for(int i=0; i<y.size(); ++i) 27 + for (int j = i+1; j < y.size(); j++) 28 + { 29 + if(y[i] != y[j]) { 30 + int er = 0; 31 + for (int k = i+1; k < j; k++) 32 + if( min(y[i],y[j])<y[k] && y[k]<max(y[i],y[j]) ) 33 + ++er; 34 + ans = max(ans, er); 35 + } 36 + } 37 + return ans; 38 + } 39 +}; 40 + 41 +// BEGIN CUT HERE 42 +#include <ctime> 43 +double start_time; string timer() 44 + { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 45 +template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 46 + { os << "{ "; 47 + for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 48 + os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 49 +void verify_case(const int& Expected, const int& Received) { 50 + bool ok = (Expected == Received); 51 + if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 52 + cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 53 +#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 54 +#define END verify_case(_, PointErasingTwo().getMaximum(y));} 55 +int main(){ 56 + 57 +CASE(0) 58 + int y_[] = { 1, 2, 1, 1, 0, 4, 3 }; 59 + vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 60 + int _ = 2; 61 +END 62 +CASE(1) 63 + int y_[] = { 0, 1 }; 64 + vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 65 + int _ = 0; 66 +END 67 +CASE(2) 68 + int y_[] = { 0, 1, 2, 3, 4 }; 69 + vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 70 + int _ = 3; 71 +END 72 +CASE(3) 73 + int y_[] = { 10, 19, 10, 19 }; 74 + vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 75 + int _ = 0; 76 +END 77 +CASE(4) 78 + int y_[] = { 0, 23, 49, 50, 32, 0, 18, 50, 0, 28, 50, 27, 49, 0 }; 79 + vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 80 + int _ = 5; 81 +END 82 +/* 83 +CASE(5) 84 + int y_[] = ; 85 + vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 86 + int _ = ; 87 +END 88 +CASE(6) 89 + int y_[] = ; 90 + vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 91 + int _ = ; 92 +END 93 +*/ 94 +} 95 +// END CUT HERE

Added SRM/522-U/2C.cpp version [54a6027b9b62c48a]

1 +#include <iostream> 2 +#include <sstream> 3 +#include <iomanip> 4 +#include <vector> 5 +#include <string> 6 +#include <map> 7 +#include <set> 8 +#include <algorithm> 9 +#include <numeric> 10 +#include <iterator> 11 +#include <functional> 12 +#include <complex> 13 +#include <queue> 14 +#include <stack> 15 +#include <cmath> 16 +#include <cassert> 17 +#include <cstring> 18 +using namespace std; 19 +typedef long long LL; 20 +typedef complex<double> CMP; 21 + 22 +class CorrectMultiplicationTwo { public: 23 + int getMinimum(int a, int b, int c) 24 + { 25 + LL score = 1LL<<62; 26 + if(a>b) swap(a,b); 27 + int Amax = int(sqrt((double)c))+999; 28 + for (int A = 1; A <= Amax; A++) 29 + { 30 + for (int B = c/A-10; B <= c/A+10; B++) 31 + { 32 + if( B > 0 ) 33 + score = min(score, abs(A-a)+abs(B-b)+abs(LL(A)*B-c)); 34 + } 35 + } 36 + return score; 37 + } 38 +}; 39 + 40 +// BEGIN CUT HERE 41 +#include <ctime> 42 +double start_time; string timer() 43 + { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 44 +template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 45 + { os << "{ "; 46 + for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 47 + os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 48 +void verify_case(const int& Expected, const int& Received) { 49 + bool ok = (Expected == Received); 50 + if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 51 + cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 52 +#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 53 +#define END verify_case(_, CorrectMultiplicationTwo().getMinimum(a, b, c));} 54 +int main(){ 55 + 56 +CASE(0) 57 + int a = 19; 58 + int b = 28; 59 + int c = 522; 60 + int _ = 2; 61 +END 62 +CASE(1) 63 + int a = 10; 64 + int b = 30; 65 + int c = 500; 66 + int _ = 11; 67 +END 68 +CASE(2) 69 + int a = 111; 70 + int b = 111; 71 + int c = 12321; 72 + int _ = 0; 73 +END 74 +CASE(3) 75 + int a = 1000; 76 + int b = 100; 77 + int c = 10; 78 + int _ = 1089; 79 +END 80 +CASE(4) 81 + int a = 399; 82 + int b = 522; 83 + int c = 199999; 84 + int _ = 24; 85 +END 86 +/* 87 +CASE(5) 88 + int a = ; 89 + int b = ; 90 + int c = ; 91 + int _ = ; 92 +END 93 +CASE(6) 94 + int a = ; 95 + int b = ; 96 + int c = ; 97 + int _ = ; 98 +END 99 +*/ 100 +} 101 +// END CUT HERE