#include #include #ifdef LOCAL #include "dump.hpp" #else #define dump(...) #endif using namespace std; #define REP(i, a, b) for(int i = (a); i < int(b); ++i) #define rep(i, n) REP(i, 0, n) #define ALL(x) begin(x), end(x) template inline void chmax(T &a, const T &b) { if(a < b) a = b; } template inline void chmin(T &a, const T &b) { if(a > b) a = b; } unsigned seed128[4]; inline void seed(unsigned s){ for(int i=1; i<=4; i++) { seed128[i-1] = s = 1812433253U * (s^(s>>30)) + i; } } inline unsigned xor_shift() { unsigned t; t=(seed128[0]^(seed128[0]<<11)); seed128[0]=seed128[1]; seed128[1]=seed128[2]; seed128[2]=seed128[3]; return seed128[3]=(seed128[3]^(seed128[3]>>19))^(t^(t>>8)); } constexpr double LIMIT = 3.0; int n; double pa, pb; vector a, b; inline double sec() { struct timeval tv; gettimeofday(&tv, NULL); return tv.tv_sec + tv.tv_usec * 1e-6; } inline int choice(double p, vector &card) { int idx = -1; if(card.size() == 1 || (double)xor_shift() / UINT_MAX < p) { idx = 0; } else { idx = xor_shift() % (card.size() - 1) + 1; } const int res = card[idx]; card.erase(begin(card) + idx); //swap(card[idx], card.back()); //card.pop_back(); return res; } inline int simulate() { int score_a = 0, score_b = 0; vector card_a(a), card_b(b); for(int i = 0; i < n; ++i) { const int ca = choice(pa, card_a); const int cb = choice(pb, card_b); if(ca > cb) { score_a += ca + cb; } else { score_b += ca + cb; } } return score_a > score_b; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(10); const auto start = sec(); seed(1940401); cin >> n >> pa >> pb; a.resize(n); b.resize(n); for(auto &e : a) cin >> e; for(auto &e : b) cin >> e; sort(begin(a), end(a)); sort(begin(b), end(b)); int win = 0; int cnt = 0; while(sec() - start < LIMIT - 0.2) { win += simulate(); ++cnt; } cout << (double)win / cnt << endl; return EXIT_SUCCESS; }