f6e551e04b 2012-05-19 kinaba: #include <iostream> f6e551e04b 2012-05-19 kinaba: #include <sstream> f6e551e04b 2012-05-19 kinaba: #include <iomanip> f6e551e04b 2012-05-19 kinaba: #include <vector> f6e551e04b 2012-05-19 kinaba: #include <string> f6e551e04b 2012-05-19 kinaba: #include <map> f6e551e04b 2012-05-19 kinaba: #include <set> f6e551e04b 2012-05-19 kinaba: #include <algorithm> f6e551e04b 2012-05-19 kinaba: #include <numeric> f6e551e04b 2012-05-19 kinaba: #include <iterator> f6e551e04b 2012-05-19 kinaba: #include <functional> f6e551e04b 2012-05-19 kinaba: #include <complex> f6e551e04b 2012-05-19 kinaba: #include <queue> f6e551e04b 2012-05-19 kinaba: #include <stack> f6e551e04b 2012-05-19 kinaba: #include <cmath> f6e551e04b 2012-05-19 kinaba: #include <cassert> f6e551e04b 2012-05-19 kinaba: #include <cstring> f6e551e04b 2012-05-19 kinaba: #ifdef __GNUC__ f6e551e04b 2012-05-19 kinaba: #include <ext/hash_map> f6e551e04b 2012-05-19 kinaba: #define unordered_map __gnu_cxx::hash_map f6e551e04b 2012-05-19 kinaba: #else f6e551e04b 2012-05-19 kinaba: #include <unordered_map> f6e551e04b 2012-05-19 kinaba: #endif f6e551e04b 2012-05-19 kinaba: using namespace std; f6e551e04b 2012-05-19 kinaba: typedef long long LL; f6e551e04b 2012-05-19 kinaba: typedef complex<double> CMP; f6e551e04b 2012-05-19 kinaba: f6e551e04b 2012-05-19 kinaba: class BlurredDartboard { public: f6e551e04b 2012-05-19 kinaba: int minThrows(vector <int> points, int P) f6e551e04b 2012-05-19 kinaba: { f6e551e04b 2012-05-19 kinaba: const int N = points.size(); f6e551e04b 2012-05-19 kinaba: f6e551e04b 2012-05-19 kinaba: int VisibleMax = *max_element(points.begin(), points.end()); f6e551e04b 2012-05-19 kinaba: f6e551e04b 2012-05-19 kinaba: vector<int> hidden; f6e551e04b 2012-05-19 kinaba: for(int x=1; x<=N; ++x) f6e551e04b 2012-05-19 kinaba: if( count(points.begin(), points.end(), x) == 0 ) f6e551e04b 2012-05-19 kinaba: hidden.push_back(x); f6e551e04b 2012-05-19 kinaba: f6e551e04b 2012-05-19 kinaba: int K = hidden.size(); f6e551e04b 2012-05-19 kinaba: if( hidden.empty() || hidden.back() < VisibleMax ) f6e551e04b 2012-05-19 kinaba: return (P+VisibleMax-1) / VisibleMax; f6e551e04b 2012-05-19 kinaba: f6e551e04b 2012-05-19 kinaba: partial_sum(hidden.begin(), hidden.end(), hidden.begin()); f6e551e04b 2012-05-19 kinaba: vector<int> vis; f6e551e04b 2012-05-19 kinaba: for(int i=1; i<=K; ++i) f6e551e04b 2012-05-19 kinaba: vis.push_back(i*VisibleMax); f6e551e04b 2012-05-19 kinaba: f6e551e04b 2012-05-19 kinaba: int turn = max(vis.back(), hidden.back()); f6e551e04b 2012-05-19 kinaba: int n = (P/turn)*K; f6e551e04b 2012-05-19 kinaba: if(P%turn) { f6e551e04b 2012-05-19 kinaba: ++n; f6e551e04b 2012-05-19 kinaba: for(int i=0; max(vis[i],hidden[i]) < (P%turn); ++i) f6e551e04b 2012-05-19 kinaba: ++n; f6e551e04b 2012-05-19 kinaba: } f6e551e04b 2012-05-19 kinaba: return n; f6e551e04b 2012-05-19 kinaba: } f6e551e04b 2012-05-19 kinaba: }; f6e551e04b 2012-05-19 kinaba: f6e551e04b 2012-05-19 kinaba: // BEGIN CUT HERE f6e551e04b 2012-05-19 kinaba: #include <ctime> f6e551e04b 2012-05-19 kinaba: double start_time; string timer() f6e551e04b 2012-05-19 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } f6e551e04b 2012-05-19 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) f6e551e04b 2012-05-19 kinaba: { os << "{ "; f6e551e04b 2012-05-19 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) f6e551e04b 2012-05-19 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } f6e551e04b 2012-05-19 kinaba: void verify_case(const int& Expected, const int& Received) { f6e551e04b 2012-05-19 kinaba: bool ok = (Expected == Received); f6e551e04b 2012-05-19 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; f6e551e04b 2012-05-19 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } f6e551e04b 2012-05-19 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); f6e551e04b 2012-05-19 kinaba: #define END verify_case(_, BlurredDartboard().minThrows(points, P));} f6e551e04b 2012-05-19 kinaba: int main(){ f6e551e04b 2012-05-19 kinaba: f6e551e04b 2012-05-19 kinaba: CASE(0) f6e551e04b 2012-05-19 kinaba: int points_[] = {0, 3, 4, 0, 0}; f6e551e04b 2012-05-19 kinaba: vector <int> points(points_, points_+sizeof(points_)/sizeof(*points_)); f6e551e04b 2012-05-19 kinaba: int P = 8; f6e551e04b 2012-05-19 kinaba: int _ = 2; f6e551e04b 2012-05-19 kinaba: END f6e551e04b 2012-05-19 kinaba: CASE(1) f6e551e04b 2012-05-19 kinaba: int points_[] = {0, 0, 0, 0, 0}; f6e551e04b 2012-05-19 kinaba: vector <int> points(points_, points_+sizeof(points_)/sizeof(*points_)); f6e551e04b 2012-05-19 kinaba: int P = 15; f6e551e04b 2012-05-19 kinaba: int _ = 5; f6e551e04b 2012-05-19 kinaba: END f6e551e04b 2012-05-19 kinaba: CASE(2) f6e551e04b 2012-05-19 kinaba: int points_[] = {4, 7, 8, 1, 3, 2, 6, 5}; f6e551e04b 2012-05-19 kinaba: vector <int> points(points_, points_+sizeof(points_)/sizeof(*points_)); f6e551e04b 2012-05-19 kinaba: int P = 2012; f6e551e04b 2012-05-19 kinaba: int _ = 252; f6e551e04b 2012-05-19 kinaba: END f6e551e04b 2012-05-19 kinaba: CASE(3) f6e551e04b 2012-05-19 kinaba: int points_[] = {0, 0, 5, 0, 0, 0, 1, 3, 0, 0}; f6e551e04b 2012-05-19 kinaba: vector <int> points(points_, points_+sizeof(points_)/sizeof(*points_)); f6e551e04b 2012-05-19 kinaba: int P = 2012; f6e551e04b 2012-05-19 kinaba: int _ = 307; f6e551e04b 2012-05-19 kinaba: END f6e551e04b 2012-05-19 kinaba: CASE(4) f6e551e04b 2012-05-19 kinaba: int points_[] = {0, 2, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 6, 0, 0, 0, 4, 0, 0, 0}; f6e551e04b 2012-05-19 kinaba: vector <int> points(points_, points_+sizeof(points_)/sizeof(*points_)); f6e551e04b 2012-05-19 kinaba: int P = 1000000000; f6e551e04b 2012-05-19 kinaba: int _ = 84656087; f6e551e04b 2012-05-19 kinaba: END f6e551e04b 2012-05-19 kinaba: CASE(5) f6e551e04b 2012-05-19 kinaba: int points_[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; f6e551e04b 2012-05-19 kinaba: vector <int> points(points_, points_+sizeof(points_)/sizeof(*points_)); f6e551e04b 2012-05-19 kinaba: int P = 1000000000; f6e551e04b 2012-05-19 kinaba: int _ = -1; f6e551e04b 2012-05-19 kinaba: END f6e551e04b 2012-05-19 kinaba: /* f6e551e04b 2012-05-19 kinaba: CASE(6) f6e551e04b 2012-05-19 kinaba: int points_[] = ; f6e551e04b 2012-05-19 kinaba: vector <int> points(points_, points_+sizeof(points_)/sizeof(*points_)); f6e551e04b 2012-05-19 kinaba: int P = ; f6e551e04b 2012-05-19 kinaba: int _ = ; f6e551e04b 2012-05-19 kinaba: END f6e551e04b 2012-05-19 kinaba: */ f6e551e04b 2012-05-19 kinaba: } f6e551e04b 2012-05-19 kinaba: // END CUT HERE