Overview
SHA1 Hash: | 1e11150f2a79c706679fb7da54d12c59af3664de |
---|---|
Date: | 2014-02-26 01:51:14 |
User: | kinaba |
Comment: | 609 |
Timelines: | family | ancestors | descendants | both | trunk |
Downloads: | Tarball | ZIP archive |
Other Links: | files | file ages | manifest |
Tags And Properties
- branch=trunk inherited from [9165bd3629]
- sym-trunk inherited from [9165bd3629]
Changes
Added SRM/609-U/1A.cpp version [672e9b49bba83305]
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 <tuple> 18 +using namespace std; 19 +typedef long long LL; 20 +typedef complex<double> CMP; 21 + 22 +class MagicalStringDiv1 { public: 23 + int getLongest(string S) 24 + { 25 + int best = 0; 26 + for(int rBegin=0; rBegin<S.size(); ++rBegin) 27 + { 28 + int l = count(S.begin(), S.begin()+rBegin, '>'); 29 + int r = count(S.begin()+rBegin, S.end(), '<'); 30 + best = max(best, 2*min(l,r)); 31 + } 32 + return best; 33 + } 34 +}; 35 + 36 +// BEGIN CUT HERE 37 +#include <ctime> 38 +double start_time; string timer() 39 + { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 40 +template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 41 + { os << "{ "; 42 + for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 43 + os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 44 +void verify_case(const int& Expected, const int& Received) { 45 + bool ok = (Expected == Received); 46 + if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 47 + cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 48 +#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 49 +#define END verify_case(_, MagicalStringDiv1().getLongest(S));} 50 +int main(){ 51 + 52 +CASE(0) 53 + string S = "<><><<>"; 54 + int _ = 4; 55 +END 56 +CASE(1) 57 + string S = ">>><<<"; 58 + int _ = 6; 59 +END 60 +CASE(2) 61 + string S = "<<<>>>"; 62 + int _ = 0; 63 +END 64 +CASE(3) 65 + string S = "<<<<><>>><>>><>><>><>>><<<<>><>>>>><<>>>>><><<<<>>"; 66 + int _ = 24; 67 +END 68 +/* 69 +CASE(4) 70 + string S = ; 71 + int _ = ; 72 +END 73 +CASE(5) 74 + string S = ; 75 + int _ = ; 76 +END 77 +*/ 78 +} 79 +// END CUT HERE
Added SRM/609-U/1B.cpp version [c67a7cb6c46a504e]
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 <tuple> 18 +using namespace std; 19 +typedef long long LL; 20 +typedef complex<double> CMP; 21 + 22 +class PackingBallsDiv1 { public: 23 + int minPacks(int K, int A, int B, int C, int D) 24 + { 25 + vector<int> X(K); 26 + X[0] = A; 27 + for(int i=1; i<K; ++i) 28 + X[i] = int((LL(X[i-1]) * B + C) % D + 1); 29 + 30 + int base = 0; 31 + for(int i=0; i<K; ++i) { 32 + base += X[i] / K; 33 + X[i] %= K; 34 + } 35 + sort(X.begin(), X.end()); 36 + 37 + int i = 0; while(i<X.size() && X[i]==0) i++; 38 + 39 + int best = base + X.size()-i; 40 + for(; i<X.size(); ++i) 41 + best = min<int>(best, base + X[i] + X.size()-i-1); 42 + return best; 43 + } 44 +}; 45 + 46 +// BEGIN CUT HERE 47 +#include <ctime> 48 +double start_time; string timer() 49 + { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 50 +template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 51 + { os << "{ "; 52 + for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 53 + os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 54 +void verify_case(const int& Expected, const int& Received) { 55 + bool ok = (Expected == Received); 56 + if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 57 + cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 58 +#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 59 +#define END verify_case(_, PackingBallsDiv1().minPacks(K, A, B, C, D));} 60 +int main(){ 61 + 62 +CASE(0) 63 + int K = 3; 64 + int A = 4; 65 + int B = 2; 66 + int C = 5; 67 + int D = 6; 68 + int _ = 4; 69 +END 70 +CASE(1) 71 + int K = 1; 72 + int A = 58; 73 + int B = 23; 74 + int C = 39; 75 + int D = 93; 76 + int _ = 58; 77 +END 78 +CASE(2) 79 + int K = 23; 80 + int A = 10988; 81 + int B = 5573; 82 + int C = 4384; 83 + int D = 100007; 84 + int _ = 47743; 85 +END 86 +CASE(3) 87 + int K = 100000; 88 + int A = 123456789; 89 + int B = 234567890; 90 + int C = 345678901; 91 + int D = 1000000000; 92 + int _ = 331988732; 93 +END 94 +/* 95 +CASE(4) 96 + int K = ; 97 + int A = ; 98 + int B = ; 99 + int C = ; 100 + int D = ; 101 + int _ = ; 102 +END 103 +CASE(5) 104 + int K = ; 105 + int A = ; 106 + int B = ; 107 + int C = ; 108 + int D = ; 109 + int _ = ; 110 +END 111 +*/ 112 +} 113 +// END CUT HERE