Artifact Content
Not logged in

Artifact d3e4a91d474c99ac8f73b781ac1f9ef4af6a0610


#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 <tuple>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class GreaterGame { public:
	double calc(vector <int> hand, vector <int> sothe)
	{
		const int N = hand.size();

		set<int> me, you, rest;
		for(int c=1; c<=2*N; ++c) rest.insert(c);
		for(int c: hand) me.insert(c), rest.erase(c);
		for(int c: sothe) you.insert(c), rest.erase(c);

		double ans = 0.0;
		while(!you.empty() && *you.rbegin()>0)
		{
			int y = *you.rbegin(); you.erase(y);

			auto it = me.rbegin();
			if(*it > y) {
				while(*it>y) {
					auto kt = it;
					++kt;
					if(kt==me.rend() || *kt<y)
						break;
					it = kt;
				}
				me.erase(*it);
				++ans;
			} else {
				me.erase(me.begin());
			}
		}

		for(int c: me)
			ans += count_if(rest.begin(), rest.end(), [&](int y){return y<c;}) / (double)rest.size();
		return ans;
	}
};

// 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 double& Expected, const double& Received) {
 bool ok = (abs(Expected - Received) < 1e-9);
 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(_, GreaterGame().calc(hand, sothe));}
int main(){

CASE(0)
	int hand_[] = {4,2};
	  vector <int> hand(hand_, hand_+sizeof(hand_)/sizeof(*hand_)); 
	int sothe_[] = {-1,-1};
	  vector <int> sothe(sothe_, sothe_+sizeof(sothe_)/sizeof(*sothe_)); 
	double _ = 1.5; 
END
CASE(1)
	int hand_[] = {4,2};
	  vector <int> hand(hand_, hand_+sizeof(hand_)/sizeof(*hand_)); 
	int sothe_[] = {1,3};
	  vector <int> sothe(sothe_, sothe_+sizeof(sothe_)/sizeof(*sothe_)); 
	double _ = 2.0; 
END
CASE(2)
	int hand_[] = {2};
	  vector <int> hand(hand_, hand_+sizeof(hand_)/sizeof(*hand_)); 
	int sothe_[] = {-1};
	  vector <int> sothe(sothe_, sothe_+sizeof(sothe_)/sizeof(*sothe_)); 
	double _ = 1.0; 
END
CASE(3)
	int hand_[] = {1,3,5,7};
	  vector <int> hand(hand_, hand_+sizeof(hand_)/sizeof(*hand_)); 
	int sothe_[] = {8,-1,4,-1};
	  vector <int> sothe(sothe_, sothe_+sizeof(sothe_)/sizeof(*sothe_)); 
	double _ = 2.5; 
END
CASE(4)
	int hand_[] = {6,12,17,14,20,8,16,7,2,15};
	  vector <int> hand(hand_, hand_+sizeof(hand_)/sizeof(*hand_)); 
	int sothe_[] = {-1,-1,4,-1,11,3,13,-1,-1,18};
	  vector <int> sothe(sothe_, sothe_+sizeof(sothe_)/sizeof(*sothe_)); 
	double _ = 8.0; 
END
/*
CASE(5)
	int hand_[] = ;
	  vector <int> hand(hand_, hand_+sizeof(hand_)/sizeof(*hand_)); 
	int sothe_[] = ;
	  vector <int> sothe(sothe_, sothe_+sizeof(sothe_)/sizeof(*sothe_)); 
	double _ = ; 
END
CASE(6)
	int hand_[] = ;
	  vector <int> hand(hand_, hand_+sizeof(hand_)/sizeof(*hand_)); 
	int sothe_[] = ;
	  vector <int> sothe(sothe_, sothe_+sizeof(sothe_)/sizeof(*sothe_)); 
	double _ = ; 
END
*/
}
// END CUT HERE