Artifact Content
Not logged in

Artifact 9a6b2ff88d4819cc5afb72bdf1f02d1f09b0f75f


#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <cstring>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class BatchSystemRoulette { public:
	vector <double> expectedFinishTimes(vector <int> duration, vector <string> user) 
	{
		vector<double> answer(duration.begin(), duration.end());

		map<string, LL> userSum;
		for(int i=0; i<user.size(); ++i)
			userSum[user[i]] += duration[i];
		map<LL, vector<string> > usInv;
		for(map<string,LL>::iterator it=userSum.begin(); it!=userSum.end(); ++it)
			usInv[it->second].push_back(it->first);

		double base = 0;
		for(map<LL, vector<string> >::iterator it=usInv.begin(); it!=usInv.end(); ++it)
		{
			LL t = it->first;
			vector<string>& us = it->second;
			int n = us.size();

			double baseAve = base + t*(n-1)/2.0;
			for(int u=0; u<n; ++u)
			{
				vector<int> idxs;
				for(int i=0; i<answer.size(); ++i)
					if( user[i] == us[u] ) {
						answer[i] += baseAve;
						idxs.push_back(i);
					}
				for(int k=0; k<idxs.size(); ++k) {
					int i = idxs[k];
					for(int m=0; m<idxs.size(); ++m) if(m!=k) {
						int j = idxs[m];
						answer[i] += duration[j]/2.0;
					}
				}
			}

			base += t*n;
		}

		return answer;
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const vector <double>& Expected, const vector <double>& Received) {
 bool ok = true;
 for(int i=0; i<Expected.size(); ++i)
   if( abs(Expected[i]-Received[i]) >= 1e-9 )
     ok = false;
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: " << Expected << endl << "\tx: " << Received << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, BatchSystemRoulette().expectedFinishTimes(duration, user));}
int main(){

CASE(0)
	int duration_[] = {3, 2, 4, 1};
	  vector <int> duration(duration_, duration_+sizeof(duration_)/sizeof(*duration_)); 
	string user_[] = {"Gil Grissom", "Sarah Sidle", "Warrick Brown", "Catherine Willows"};
	  vector <string> user(user_, user_+sizeof(user_)/sizeof(*user_)); 
	double __[] = {6.0, 3.0, 10.0, 1.0 };
	  vector <double> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(1)
	int duration_[] = {3, 2, 4, 1};
	  vector <int> duration(duration_, duration_+sizeof(duration_)/sizeof(*duration_)); 
	string user_[] = {"mac taylor", "Mac Taylor", "Mac Taylor", "Peyton Driscoll"};
	  vector <string> user(user_, user_+sizeof(user_)/sizeof(*user_)); 
	double __[] = {4.0, 8.0, 9.0, 1.0 };
	  vector <double> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(2)
	int duration_[] = {13, 14, 15, 56, 56};
	  vector <int> duration(duration_, duration_+sizeof(duration_)/sizeof(*duration_)); 
	string user_[] = {"Tim Speedle", "Tim Speedle", "Tim Speedle", "Horatio Caine", "YEEEAAAAAAAAAAH"};
	  vector <string> user(user_, user_+sizeof(user_)/sizeof(*user_)); 
	double __[] = {27.5, 28.0, 28.5, 126.0, 126.0 };
	  vector <double> _(__, __+sizeof(__)/sizeof(*__)); 
END
/*
CASE(3)
	int duration_[] = ;
	  vector <int> duration(duration_, duration_+sizeof(duration_)/sizeof(*duration_)); 
	string user_[] = ;
	  vector <string> user(user_, user_+sizeof(user_)/sizeof(*user_)); 
	double __[] = ;
	  vector <double> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(4)
	int duration_[] = ;
	  vector <int> duration(duration_, duration_+sizeof(duration_)/sizeof(*duration_)); 
	string user_[] = ;
	  vector <string> user(user_, user_+sizeof(user_)/sizeof(*user_)); 
	double __[] = ;
	  vector <double> _(__, __+sizeof(__)/sizeof(*__)); 
END
*/
}
// END CUT HERE