CodeChef submission 64961 (C++ 4.0.0-8) plaintext list. Status: AC, problem F6, contest AUG09. By gmark (Mark Greve), 2009-08-05 17:39:46.
// Divide and Conquer // Source: CodeChef August 2009 Algorithm Challenge // CodeChef ID: F6 // Date: 03-08-2009 // Author: Mark Greve #include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define MP make_pair typedef pair<double, double> pdd; const double EPS=1e-9; void verify_sol(double k, const vector<pair<int, double> >& v) { vector<pair<double,int> > p; p.push_back(MP(1.0, 0)); int cnt = 1; for (int i=0;i<v.size();++i) { for (int j=0;j<p.size();++j) if (v[i].first==p[j].first) { pair<double,int> x = p[j]; p.erase(p.begin()+j); p.push_back(MP(v[i].second, cnt)); p.push_back(MP(x.second - v[i].second, x.first)); break; } sort(p.begin(),p.end()); } } void solve(double k) { //cout << "K " << k << endl; int d; --d; d *= 2; //cout << "\tD " << d << endl; //cout << "\tR " << r << endl; int vars = (d+1)/2; //cout << "\tVARS " << vars << endl; vector<pdd> l; double z = x; for (int i=0;i<2*vars;++i) { l.push_back(MP(z,z)); //cout << "\tPUSH " << z << endl; if (i%2==1) z *= r; } vector<pdd> v; while (l.size()>1) { pdd a = l[0]; pdd b = l[1]; l.erase(l.begin(),l.begin()+2); //cout << "\tPPP " << a.second << " other " << b.second << " sum " << a.second + b.second << endl; v.push_back(MP(a.second, a.second + b.second)); l.push_back(MP(a.second, a.second + b.second)); } vector<int> idx; idx.push_back(0); reverse(v.begin(),v.end()); int cnt = 0; vector<pair<int, double> > sol; for (int i=0;i<v.size();++i) { int id = idx[cnt]; ++cnt; sol.push_back(MP(id,v[i].first)); idx.push_back(id); idx.push_back(cnt); } //verify_sol(k, sol); }
Comments

