Overview
SHA1 Hash: | 7448b5f6109dbbd2b0dcacdb33f53694262dee49 |
---|---|
Date: | 2012-11-20 15:46:29 |
User: | kinaba |
Comment: | 560 |
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/560-U/1A.cpp version [ea24c81619e0b85d]
> 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 using namespace std; > 18 typedef long long LL; > 19 typedef long double LD; > 20 typedef complex<LD> CMP; > 21 > 22 class TomekPhone { public: > 23 int minKeystrokes(vector <int> fr, vector <int> keySizes) > 24 { > 25 vector<int> cand; > 26 for(int i=0; i<keySizes.size(); ++i) > 27 for(int k=1; k<=keySizes[i]; ++k) > 28 cand.push_back(k); > 29 sort(cand.begin(), cand.end()); > 30 if(cand.size() < fr.size()) > 31 return -1; > 32 > 33 int total = 0; > 34 sort(fr.rbegin(), fr.rend()); > 35 for(int i=0; i<fr.size(); ++i) > 36 total += fr[i]*cand[i]; > 37 return total; > 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) > 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 > 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() > 52 cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' > 53 #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock( > 54 #define END verify_case(_, TomekPhone().minKeystrokes(frequencies, keySizes > 55 int main(){ > 56 > 57 CASE(0) > 58 int frequencies_[] = {7,3,4,1}; > 59 vector <int> frequencies(frequencies_, frequencies_+sizeof(frequencies > 60 int keySizes_[] = {2,2}; > 61 vector <int> keySizes(keySizes_, keySizes_+sizeof(keySizes_)/sizeof(*k > 62 int _ = 19; > 63 END > 64 CASE(1) > 65 int frequencies_[] = {13,7,4,20}; > 66 vector <int> frequencies(frequencies_, frequencies_+sizeof(frequencies > 67 int keySizes_[] = {2,1}; > 68 vector <int> keySizes(keySizes_, keySizes_+sizeof(keySizes_)/sizeof(*k > 69 int _ = -1; > 70 END > 71 CASE(2) > 72 int frequencies_[] = {11,23,4,50,1000,7,18}; > 73 vector <int> frequencies(frequencies_, frequencies_+sizeof(frequencies > 74 int keySizes_[] = {3,1,4}; > 75 vector <int> keySizes(keySizes_, keySizes_+sizeof(keySizes_)/sizeof(*k > 76 int _ = 1164; > 77 END > 78 CASE(3) > 79 int frequencies_[] = {100,1000,1,10}; > 80 vector <int> frequencies(frequencies_, frequencies_+sizeof(frequencies > 81 int keySizes_[] = {50}; > 82 vector <int> keySizes(keySizes_, keySizes_+sizeof(keySizes_)/sizeof(*k > 83 int _ = 1234; > 84 END > 85 CASE(4) > 86 int frequencies_[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 > 87 vector <int> frequencies(frequencies_, frequencies_+sizeof(frequencies > 88 int keySizes_[] = {10,10,10,10,10,10,10,10}; > 89 vector <int> keySizes(keySizes_, keySizes_+sizeof(keySizes_)/sizeof(*k > 90 int _ = 3353; > 91 END > 92 /* > 93 CASE(5) > 94 int frequencies_[] = ; > 95 vector <int> frequencies(frequencies_, frequencies_+sizeof(frequencies > 96 int keySizes_[] = ; > 97 vector <int> keySizes(keySizes_, keySizes_+sizeof(keySizes_)/sizeof(*k > 98 int _ = ; > 99 END > 100 CASE(6) > 101 int frequencies_[] = ; > 102 vector <int> frequencies(frequencies_, frequencies_+sizeof(frequencies > 103 int keySizes_[] = ; > 104 vector <int> keySizes(keySizes_, keySizes_+sizeof(keySizes_)/sizeof(*k > 105 int _ = ; > 106 END > 107 */ > 108 } > 109 // END CUT HERE
Added SRM/560-U/1B.cpp version [ba901c83080df3e4]
> 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 using namespace std; > 18 typedef long long LL; > 19 typedef long double LD; > 20 typedef complex<LD> CMP; > 21 > 22 class DrawingPointsDivOne { public: > 23 int maxSteps(vector <int> x, vector <int> y) > 24 { > 25 static const int INF = 300; > 26 int L=0, R=INF+1; > 27 while(R-L>1) { > 28 int C = (L+R)/2; > 29 (possible(x,y,C) ? L : R) = C; > 30 } > 31 return L==INF ? -1 : L; > 32 } > 33 > 34 bool possible(const vector<int>& x, const vector<int>& y, int C) > 35 { > 36 int N = x.size(); > 37 int Z = C+10+280+C+10; > 38 int MID = C+10+140; > 39 vector<int> m(Z*Z); > 40 > 41 // paint > 42 for(int i=0; i<N; ++i) { > 43 int yy = MID+y[i]*2; > 44 int xx = MID+x[i]*2; > 45 m[ (yy+C )*Z+(xx+C ) ] += 1; > 46 m[ (yy-C-2)*Z+(xx+C ) ] -= 1; > 47 m[ (yy+C )*Z+(xx-C-2) ] -= 1; > 48 m[ (yy-C-2)*Z+(xx-C-2) ] += 1; > 49 } > 50 > 51 // sum > 52 for(int y=Z-3; y>=0; --y) > 53 for(int x=Z-3; x>=0; --x) > 54 m[y*Z+x] += m[(y+2)*Z+x]+m[y*Z+(x+2)]-m[(y+2)*Z+(x+2)]; > 55 > 56 for(int y=0; y<Z; ++y) for(int x=0; x<Z; ++x) m[y*Z+x] = !!m[y*Z > 57 > 58 // sum > 59 for(int y=Z-3; y>=0; --y) > 60 for(int x=Z-3; x>=0; --x) > 61 m[y*Z+x] += m[(y+2)*Z+x]+m[y*Z+(x+2)]-m[(y+2)*Z+(x+2)]; > 62 > 63 // count > 64 int cnt = 0; > 65 int S = (MID&1); > 66 for(int yy=S; yy<Z; yy+=2) > 67 for(int xx=S; xx<Z; xx+=2) > 68 if(yy+C+2<Z && xx+C+2<Z && yy-C>=0 && xx-C>=0) { > 69 int s = > 70 +m[ (yy+C+2)*Z+(xx+C+2) ] > 71 -m[ (yy-C )*Z+(xx+C+2) ] > 72 -m[ (yy+C+2)*Z+(xx-C ) ] > 73 +m[ (yy-C )*Z+(xx-C ) ]; > 74 if(s==(C+1)*(C+1)) > 75 ++cnt; > 76 } > 77 return cnt == N; > 78 } > 79 }; > 80 > 81 // BEGIN CUT HERE > 82 #include <ctime> > 83 double start_time; string timer() > 84 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) > 85 template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) > 86 { os << "{ "; > 87 for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) > 88 os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return > 89 void verify_case(const int& Expected, const int& Received) { > 90 bool ok = (Expected == Received); > 91 if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() > 92 cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' > 93 #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock( > 94 #define END verify_case(_, DrawingPointsDivOne().maxSteps(x, y));} > 95 int main(){ > 96 > 97 CASE(0) > 98 int x_[] = {0, 3}; > 99 vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); > 100 int y_[] = {0, 0}; > 101 vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); > 102 int _ = 1; > 103 END > 104 CASE(1) > 105 int x_[] = {0,2}; > 106 vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); > 107 int y_[] = {0,0}; > 108 vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); > 109 int _ = 0; > 110 END > 111 CASE(2) > 112 int x_[] = {-70}; > 113 vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); > 114 int y_[] = {3}; > 115 vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); > 116 int _ = -1; > 117 END > 118 CASE(3) > 119 int x_[] = {-41,-40,1,-11,-32,-7,24,-11,49,-15,-22,20,-8,54,54,69,16,-30 > 120 -37,-33,-18,-35,36,9,61,-43,45,5,60,-8,-58,65,-66,41,12,34,-11,-57,-38,46,63,-5 > 121 vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); > 122 int y_[] = {5,-24,-2,-4,23,14,1,70,-26,45,15,48,32,-41,54,-47,-67,-46,-9 > 123 -33,62,37,-8,-17,-17,48,19,-49,56,-41,16,17,-50,28,59,10,50,23,-16,56,31,-70,-4 > 124 vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); > 125 int _ = 9; > 126 END > 127 /* > 128 CASE(4) > 129 int x_[] = ; > 130 vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); > 131 int y_[] = ; > 132 vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); > 133 int _ = ; > 134 END > 135 CASE(5) > 136 int x_[] = ; > 137 vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); > 138 int y_[] = ; > 139 vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); > 140 int _ = ; > 141 END > 142 */ > 143 } > 144 // END CUT HERE