339e20815a 2014-10-24 kinaba: #include <iostream> 339e20815a 2014-10-24 kinaba: #include <sstream> 339e20815a 2014-10-24 kinaba: #include <iomanip> 339e20815a 2014-10-24 kinaba: #include <vector> 339e20815a 2014-10-24 kinaba: #include <string> 339e20815a 2014-10-24 kinaba: #include <map> 339e20815a 2014-10-24 kinaba: #include <set> 339e20815a 2014-10-24 kinaba: #include <algorithm> 339e20815a 2014-10-24 kinaba: #include <numeric> 339e20815a 2014-10-24 kinaba: #include <iterator> 339e20815a 2014-10-24 kinaba: #include <functional> 339e20815a 2014-10-24 kinaba: #include <complex> 339e20815a 2014-10-24 kinaba: #include <queue> 339e20815a 2014-10-24 kinaba: #include <stack> 339e20815a 2014-10-24 kinaba: #include <cmath> 339e20815a 2014-10-24 kinaba: #include <cassert> 339e20815a 2014-10-24 kinaba: #include <tuple> 339e20815a 2014-10-24 kinaba: using namespace std; 339e20815a 2014-10-24 kinaba: typedef long long LL; 339e20815a 2014-10-24 kinaba: typedef complex<double> CMP; 339e20815a 2014-10-24 kinaba: 339e20815a 2014-10-24 kinaba: class GreaterGame { public: 339e20815a 2014-10-24 kinaba: double calc(vector <int> hand, vector <int> sothe) 339e20815a 2014-10-24 kinaba: { 339e20815a 2014-10-24 kinaba: const int N = hand.size(); 339e20815a 2014-10-24 kinaba: 339e20815a 2014-10-24 kinaba: set<int> me, you, rest; 339e20815a 2014-10-24 kinaba: for(int c=1; c<=2*N; ++c) rest.insert(c); 339e20815a 2014-10-24 kinaba: for(int c: hand) me.insert(c), rest.erase(c); 339e20815a 2014-10-24 kinaba: for(int c: sothe) you.insert(c), rest.erase(c); 339e20815a 2014-10-24 kinaba: 339e20815a 2014-10-24 kinaba: double ans = 0.0; 339e20815a 2014-10-24 kinaba: while(!you.empty() && *you.rbegin()>0) 339e20815a 2014-10-24 kinaba: { 339e20815a 2014-10-24 kinaba: int y = *you.rbegin(); you.erase(y); 339e20815a 2014-10-24 kinaba: 339e20815a 2014-10-24 kinaba: auto it = me.rbegin(); 339e20815a 2014-10-24 kinaba: if(*it > y) { 339e20815a 2014-10-24 kinaba: while(*it>y) { 339e20815a 2014-10-24 kinaba: auto kt = it; 339e20815a 2014-10-24 kinaba: ++kt; 339e20815a 2014-10-24 kinaba: if(kt==me.rend() || *kt<y) 339e20815a 2014-10-24 kinaba: break; 339e20815a 2014-10-24 kinaba: it = kt; 339e20815a 2014-10-24 kinaba: } 339e20815a 2014-10-24 kinaba: me.erase(*it); 339e20815a 2014-10-24 kinaba: ++ans; 339e20815a 2014-10-24 kinaba: } else { 339e20815a 2014-10-24 kinaba: me.erase(me.begin()); 339e20815a 2014-10-24 kinaba: } 339e20815a 2014-10-24 kinaba: } 339e20815a 2014-10-24 kinaba: 339e20815a 2014-10-24 kinaba: for(int c: me) 339e20815a 2014-10-24 kinaba: ans += count_if(rest.begin(), rest.end(), [&](int y){return y<c;}) / (double)rest.size(); 339e20815a 2014-10-24 kinaba: return ans; 339e20815a 2014-10-24 kinaba: } 339e20815a 2014-10-24 kinaba: }; 339e20815a 2014-10-24 kinaba: 339e20815a 2014-10-24 kinaba: // BEGIN CUT HERE 339e20815a 2014-10-24 kinaba: #include <ctime> 339e20815a 2014-10-24 kinaba: double start_time; string timer() 339e20815a 2014-10-24 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 339e20815a 2014-10-24 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 339e20815a 2014-10-24 kinaba: { os << "{ "; 339e20815a 2014-10-24 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 339e20815a 2014-10-24 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 339e20815a 2014-10-24 kinaba: void verify_case(const double& Expected, const double& Received) { 339e20815a 2014-10-24 kinaba: bool ok = (abs(Expected - Received) < 1e-9); 339e20815a 2014-10-24 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 339e20815a 2014-10-24 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 339e20815a 2014-10-24 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 339e20815a 2014-10-24 kinaba: #define END verify_case(_, GreaterGame().calc(hand, sothe));} 339e20815a 2014-10-24 kinaba: int main(){ 339e20815a 2014-10-24 kinaba: 339e20815a 2014-10-24 kinaba: CASE(0) 339e20815a 2014-10-24 kinaba: int hand_[] = {4,2}; 339e20815a 2014-10-24 kinaba: vector <int> hand(hand_, hand_+sizeof(hand_)/sizeof(*hand_)); 339e20815a 2014-10-24 kinaba: int sothe_[] = {-1,-1}; 339e20815a 2014-10-24 kinaba: vector <int> sothe(sothe_, sothe_+sizeof(sothe_)/sizeof(*sothe_)); 339e20815a 2014-10-24 kinaba: double _ = 1.5; 339e20815a 2014-10-24 kinaba: END 339e20815a 2014-10-24 kinaba: CASE(1) 339e20815a 2014-10-24 kinaba: int hand_[] = {4,2}; 339e20815a 2014-10-24 kinaba: vector <int> hand(hand_, hand_+sizeof(hand_)/sizeof(*hand_)); 339e20815a 2014-10-24 kinaba: int sothe_[] = {1,3}; 339e20815a 2014-10-24 kinaba: vector <int> sothe(sothe_, sothe_+sizeof(sothe_)/sizeof(*sothe_)); 339e20815a 2014-10-24 kinaba: double _ = 2.0; 339e20815a 2014-10-24 kinaba: END 339e20815a 2014-10-24 kinaba: CASE(2) 339e20815a 2014-10-24 kinaba: int hand_[] = {2}; 339e20815a 2014-10-24 kinaba: vector <int> hand(hand_, hand_+sizeof(hand_)/sizeof(*hand_)); 339e20815a 2014-10-24 kinaba: int sothe_[] = {-1}; 339e20815a 2014-10-24 kinaba: vector <int> sothe(sothe_, sothe_+sizeof(sothe_)/sizeof(*sothe_)); 339e20815a 2014-10-24 kinaba: double _ = 1.0; 339e20815a 2014-10-24 kinaba: END 339e20815a 2014-10-24 kinaba: CASE(3) 339e20815a 2014-10-24 kinaba: int hand_[] = {1,3,5,7}; 339e20815a 2014-10-24 kinaba: vector <int> hand(hand_, hand_+sizeof(hand_)/sizeof(*hand_)); 339e20815a 2014-10-24 kinaba: int sothe_[] = {8,-1,4,-1}; 339e20815a 2014-10-24 kinaba: vector <int> sothe(sothe_, sothe_+sizeof(sothe_)/sizeof(*sothe_)); 339e20815a 2014-10-24 kinaba: double _ = 2.5; 339e20815a 2014-10-24 kinaba: END 339e20815a 2014-10-24 kinaba: CASE(4) 339e20815a 2014-10-24 kinaba: int hand_[] = {6,12,17,14,20,8,16,7,2,15}; 339e20815a 2014-10-24 kinaba: vector <int> hand(hand_, hand_+sizeof(hand_)/sizeof(*hand_)); 339e20815a 2014-10-24 kinaba: int sothe_[] = {-1,-1,4,-1,11,3,13,-1,-1,18}; 339e20815a 2014-10-24 kinaba: vector <int> sothe(sothe_, sothe_+sizeof(sothe_)/sizeof(*sothe_)); 339e20815a 2014-10-24 kinaba: double _ = 8.0; 339e20815a 2014-10-24 kinaba: END 339e20815a 2014-10-24 kinaba: /* 339e20815a 2014-10-24 kinaba: CASE(5) 339e20815a 2014-10-24 kinaba: int hand_[] = ; 339e20815a 2014-10-24 kinaba: vector <int> hand(hand_, hand_+sizeof(hand_)/sizeof(*hand_)); 339e20815a 2014-10-24 kinaba: int sothe_[] = ; 339e20815a 2014-10-24 kinaba: vector <int> sothe(sothe_, sothe_+sizeof(sothe_)/sizeof(*sothe_)); 339e20815a 2014-10-24 kinaba: double _ = ; 339e20815a 2014-10-24 kinaba: END 339e20815a 2014-10-24 kinaba: CASE(6) 339e20815a 2014-10-24 kinaba: int hand_[] = ; 339e20815a 2014-10-24 kinaba: vector <int> hand(hand_, hand_+sizeof(hand_)/sizeof(*hand_)); 339e20815a 2014-10-24 kinaba: int sothe_[] = ; 339e20815a 2014-10-24 kinaba: vector <int> sothe(sothe_, sothe_+sizeof(sothe_)/sizeof(*sothe_)); 339e20815a 2014-10-24 kinaba: double _ = ; 339e20815a 2014-10-24 kinaba: END 339e20815a 2014-10-24 kinaba: */ 339e20815a 2014-10-24 kinaba: } 339e20815a 2014-10-24 kinaba: // END CUT HERE