744af0f22d 2014-07-26 kinaba: #include <iostream> 744af0f22d 2014-07-26 kinaba: #include <sstream> 744af0f22d 2014-07-26 kinaba: #include <iomanip> 744af0f22d 2014-07-26 kinaba: #include <vector> 744af0f22d 2014-07-26 kinaba: #include <string> 744af0f22d 2014-07-26 kinaba: #include <map> 744af0f22d 2014-07-26 kinaba: #include <set> 744af0f22d 2014-07-26 kinaba: #include <algorithm> 744af0f22d 2014-07-26 kinaba: #include <numeric> 744af0f22d 2014-07-26 kinaba: #include <iterator> 744af0f22d 2014-07-26 kinaba: #include <functional> 744af0f22d 2014-07-26 kinaba: #include <complex> 744af0f22d 2014-07-26 kinaba: #include <queue> 744af0f22d 2014-07-26 kinaba: #include <stack> 744af0f22d 2014-07-26 kinaba: #include <cmath> 744af0f22d 2014-07-26 kinaba: #include <cassert> 744af0f22d 2014-07-26 kinaba: #include <tuple> 744af0f22d 2014-07-26 kinaba: using namespace std; 744af0f22d 2014-07-26 kinaba: typedef long long LL; 744af0f22d 2014-07-26 kinaba: typedef complex<double> CMP; 744af0f22d 2014-07-26 kinaba: 744af0f22d 2014-07-26 kinaba: class DoraemonPuzzleGame { public: 744af0f22d 2014-07-26 kinaba: double solve(vector <int> X, vector <int> Y, int m) 744af0f22d 2014-07-26 kinaba: { 744af0f22d 2014-07-26 kinaba: int N = X.size(), M = m; 744af0f22d 2014-07-26 kinaba: vector<tuple<double,double,double>> P; 744af0f22d 2014-07-26 kinaba: for(int i=0; i<N; ++i) 744af0f22d 2014-07-26 kinaba: P.emplace_back( 744af0f22d 2014-07-26 kinaba: (1000-X[i]-Y[i])*0.001, 744af0f22d 2014-07-26 kinaba: X[i]*0.001, 744af0f22d 2014-07-26 kinaba: Y[i]*0.001 744af0f22d 2014-07-26 kinaba: ); 744af0f22d 2014-07-26 kinaba: sort(P.begin(), P.end(), [&](const tuple<double,double,double>& lhs, const tuple<double,double,double>& rhs){ 744af0f22d 2014-07-26 kinaba: if(get<2>(lhs) != get<2>(rhs)) return get<2>(lhs) > get<2>(rhs); 744af0f22d 2014-07-26 kinaba: if(get<1>(lhs) != get<1>(rhs)) return get<1>(lhs) > get<1>(rhs); 744af0f22d 2014-07-26 kinaba: return get<0>(lhs) > get<0>(rhs); 744af0f22d 2014-07-26 kinaba: }); 744af0f22d 2014-07-26 kinaba: return solve(M-N, P); 744af0f22d 2014-07-26 kinaba: } 744af0f22d 2014-07-26 kinaba: 744af0f22d 2014-07-26 kinaba: double solve(int Extra, const vector<tuple<double,double,double>>& P) 744af0f22d 2014-07-26 kinaba: { 744af0f22d 2014-07-26 kinaba: double eee = 0.0; 744af0f22d 2014-07-26 kinaba: for(int eff=0; eff<=P.size(); ++eff) 744af0f22d 2014-07-26 kinaba: { 744af0f22d 2014-07-26 kinaba: double e_clear = 0.0; 744af0f22d 2014-07-26 kinaba: vector<double> adv(1, 1.0); // adv[0] = 1.0; 744af0f22d 2014-07-26 kinaba: for(int i=0; i<P.size(); ++i) { 744af0f22d 2014-07-26 kinaba: double p1 = get<1>(P[i]); 744af0f22d 2014-07-26 kinaba: double p2 = get<2>(P[i]); 744af0f22d 2014-07-26 kinaba: if(i<eff) { 744af0f22d 2014-07-26 kinaba: e_clear += 1/p2; 744af0f22d 2014-07-26 kinaba: } else { 744af0f22d 2014-07-26 kinaba: double p = p1 + p2; 744af0f22d 2014-07-26 kinaba: e_clear += 1/p; 744af0f22d 2014-07-26 kinaba: 744af0f22d 2014-07-26 kinaba: vector<double> a2(adv.size()+1); 744af0f22d 2014-07-26 kinaba: for(int i=0; i<adv.size(); ++i) { 744af0f22d 2014-07-26 kinaba: a2[i] += adv[i] * p1/p; 744af0f22d 2014-07-26 kinaba: a2[i+1] += adv[i] * p2/p; 744af0f22d 2014-07-26 kinaba: } 744af0f22d 2014-07-26 kinaba: adv = a2; 744af0f22d 2014-07-26 kinaba: } 744af0f22d 2014-07-26 kinaba: } 744af0f22d 2014-07-26 kinaba: 744af0f22d 2014-07-26 kinaba: if(Extra <= eff) { 744af0f22d 2014-07-26 kinaba: best = min(best, e_clear); 744af0f22d 2014-07-26 kinaba: } else { 744af0f22d 2014-07-26 kinaba: best = min(best, 744af0f22d 2014-07-26 kinaba: } 744af0f22d 2014-07-26 kinaba: } 744af0f22d 2014-07-26 kinaba: return eee; 744af0f22d 2014-07-26 kinaba: } 744af0f22d 2014-07-26 kinaba: }; 744af0f22d 2014-07-26 kinaba: 744af0f22d 2014-07-26 kinaba: // BEGIN CUT HERE 744af0f22d 2014-07-26 kinaba: #include <ctime> 744af0f22d 2014-07-26 kinaba: double start_time; string timer() 744af0f22d 2014-07-26 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 744af0f22d 2014-07-26 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 744af0f22d 2014-07-26 kinaba: { os << "{ "; 744af0f22d 2014-07-26 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 744af0f22d 2014-07-26 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 744af0f22d 2014-07-26 kinaba: void verify_case(const double& Expected, const double& Received) { 744af0f22d 2014-07-26 kinaba: bool ok = (abs(Expected - Received) < 1e-9); 744af0f22d 2014-07-26 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 744af0f22d 2014-07-26 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 744af0f22d 2014-07-26 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 744af0f22d 2014-07-26 kinaba: #define END verify_case(_, DoraemonPuzzleGame().solve(X, Y, m));} 744af0f22d 2014-07-26 kinaba: int main(){ 744af0f22d 2014-07-26 kinaba: 744af0f22d 2014-07-26 kinaba: CASE(0) 744af0f22d 2014-07-26 kinaba: int X_[] = {800}; 744af0f22d 2014-07-26 kinaba: vector <int> X(X_, X_+sizeof(X_)/sizeof(*X_)); 744af0f22d 2014-07-26 kinaba: int Y_[] = {200}; 744af0f22d 2014-07-26 kinaba: vector <int> Y(Y_, Y_+sizeof(Y_)/sizeof(*Y_)); 744af0f22d 2014-07-26 kinaba: int m = 2; 744af0f22d 2014-07-26 kinaba: double _ = 5.0; 744af0f22d 2014-07-26 kinaba: END 744af0f22d 2014-07-26 kinaba: CASE(1) 744af0f22d 2014-07-26 kinaba: int X_[] = {1,999,999}; 744af0f22d 2014-07-26 kinaba: vector <int> X(X_, X_+sizeof(X_)/sizeof(*X_)); 744af0f22d 2014-07-26 kinaba: int Y_[] = {999,1,1}; 744af0f22d 2014-07-26 kinaba: vector <int> Y(Y_, Y_+sizeof(Y_)/sizeof(*Y_)); 744af0f22d 2014-07-26 kinaba: int m = 3; 744af0f22d 2014-07-26 kinaba: double _ = 3.0; 744af0f22d 2014-07-26 kinaba: END 744af0f22d 2014-07-26 kinaba: CASE(2) 744af0f22d 2014-07-26 kinaba: int X_[] = {500,500}; 744af0f22d 2014-07-26 kinaba: vector <int> X(X_, X_+sizeof(X_)/sizeof(*X_)); 744af0f22d 2014-07-26 kinaba: int Y_[] = {500,500}; 744af0f22d 2014-07-26 kinaba: vector <int> Y(Y_, Y_+sizeof(Y_)/sizeof(*Y_)); 744af0f22d 2014-07-26 kinaba: int m = 3; 744af0f22d 2014-07-26 kinaba: double _ = 2.5; 744af0f22d 2014-07-26 kinaba: END 744af0f22d 2014-07-26 kinaba: CASE(3) 744af0f22d 2014-07-26 kinaba: int X_[] = {250,250,250,250}; 744af0f22d 2014-07-26 kinaba: vector <int> X(X_, X_+sizeof(X_)/sizeof(*X_)); 744af0f22d 2014-07-26 kinaba: int Y_[] = {250,250,250,250}; 744af0f22d 2014-07-26 kinaba: vector <int> Y(Y_, Y_+sizeof(Y_)/sizeof(*Y_)); 744af0f22d 2014-07-26 kinaba: int m = 5; 744af0f22d 2014-07-26 kinaba: double _ = 8.25; 744af0f22d 2014-07-26 kinaba: END 744af0f22d 2014-07-26 kinaba: CASE(4) 744af0f22d 2014-07-26 kinaba: int X_[] = {250,500,250}; 744af0f22d 2014-07-26 kinaba: vector <int> X(X_, X_+sizeof(X_)/sizeof(*X_)); 744af0f22d 2014-07-26 kinaba: int Y_[] = {500,250,500}; 744af0f22d 2014-07-26 kinaba: vector <int> Y(Y_, Y_+sizeof(Y_)/sizeof(*Y_)); 744af0f22d 2014-07-26 kinaba: int m = 5; 744af0f22d 2014-07-26 kinaba: double _ = 4.962962962962963; 744af0f22d 2014-07-26 kinaba: END 744af0f22d 2014-07-26 kinaba: CASE(5) 744af0f22d 2014-07-26 kinaba: int X_[] = {600,900,800,500,900,200,400,100,800,300,900,300,800,700,800,600,800,900,400,100,100,700,600,100,500, 744af0f22d 2014-07-26 kinaba: 800,700,600,900,600,300,100,300,100,700,500,900,200,800,400,300,700,300,400,700,300,400,800,300,200}; 744af0f22d 2014-07-26 kinaba: vector <int> X(X_, X_+sizeof(X_)/sizeof(*X_)); 744af0f22d 2014-07-26 kinaba: int Y_[] = {400,100,200,500,100,800,600,900,200,700,100,700,200,300,200,400,200,100,600,900,900,300,400,900,500, 744af0f22d 2014-07-26 kinaba: 200,300,400,100,400,700,900,700,900,300,500,100,800,200,600,700,300,700,600,300,700,600,200,700,800}; 744af0f22d 2014-07-26 kinaba: vector <int> Y(Y_, Y_+sizeof(Y_)/sizeof(*Y_)); 744af0f22d 2014-07-26 kinaba: int m = 95; 744af0f22d 2014-07-26 kinaba: double _ = 119.33578280666175; 744af0f22d 2014-07-26 kinaba: END 744af0f22d 2014-07-26 kinaba: /* 744af0f22d 2014-07-26 kinaba: CASE(6) 744af0f22d 2014-07-26 kinaba: int X_[] = ; 744af0f22d 2014-07-26 kinaba: vector <int> X(X_, X_+sizeof(X_)/sizeof(*X_)); 744af0f22d 2014-07-26 kinaba: int Y_[] = ; 744af0f22d 2014-07-26 kinaba: vector <int> Y(Y_, Y_+sizeof(Y_)/sizeof(*Y_)); 744af0f22d 2014-07-26 kinaba: int m = ; 744af0f22d 2014-07-26 kinaba: double _ = ; 744af0f22d 2014-07-26 kinaba: END 744af0f22d 2014-07-26 kinaba: CASE(7) 744af0f22d 2014-07-26 kinaba: int X_[] = ; 744af0f22d 2014-07-26 kinaba: vector <int> X(X_, X_+sizeof(X_)/sizeof(*X_)); 744af0f22d 2014-07-26 kinaba: int Y_[] = ; 744af0f22d 2014-07-26 kinaba: vector <int> Y(Y_, Y_+sizeof(Y_)/sizeof(*Y_)); 744af0f22d 2014-07-26 kinaba: int m = ; 744af0f22d 2014-07-26 kinaba: double _ = ; 744af0f22d 2014-07-26 kinaba: END 744af0f22d 2014-07-26 kinaba: */ 744af0f22d 2014-07-26 kinaba: } 744af0f22d 2014-07-26 kinaba: // END CUT HERE