// yukicoder: No.173 カードゲーム(Medium) // 2019.8.22 bal4u #include #include #include #if 1 #define gc() getchar_unlocked() #else #define gc() getchar() #endif int in() { // 非負整数の入力 int n = 0, c = gc(); do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0'); return n; } double getdbl() { // 実数の入力 int minus = 0; double x, y; int n = 0, c = gc(); if (c == '-') minus = 1, c = gc(); do n = 10*n + (c & 0xf), c = gc(); while (c >= '0'); if (c == '.') { x = 0; y = 1, c = gc(); do y *= 0.1, x += y * (c & 0xf), c = gc(); while (c >= '0'); x += n; } else x = n; if (minus) x = -x; return x; } #define MAX 1000 #define LOOP 50000 int N; int A[25], B[25]; // それぞれの最大値 double Pa, Pb; int a[25], b[25]; int cmp(const void *u, const void *v) { return *(int *)u - *(int *)v; } // 32ビット乱数を生成する unsigned int xorshift(void) { static unsigned int y = 2463534242; y = y ^ (y << 13); y = y ^ (y >> 17); y = y ^ (y << 5); return y; } static int f[25]; void setup(int *a, int *A, double P) { int i, j, k; double p; memcpy(f, A, sizeof(f)); for (i = 1; i < N; i++) { p = (xorshift() % (MAX+1)) / (double)MAX; if (p <= P) j = 0; else j = 1+(N-i)*(p-P)/(1-P); if (j > N-i) j = N-i; for (k = 0; k < N; k++) { if (f[k] && j-- == 0) { a[i-1] = f[k], f[k] = 0; break; } } } for (k = 0; k < N; k++) { if (f[k]) { a[N-1] = f[k]; break; } } } int main() { int i, loop, sa, sb, ans; N = in(), Pa = getdbl(), Pb = getdbl(); i = N; while (i--) A[i] = in(); i = N; while (i--) B[i] = in(); qsort(A, N, sizeof(int), cmp), qsort(B, N, sizeof(int), cmp); ans = 0, loop = LOOP; while (loop--) { sa = sb = 0; setup(a, A, Pa), setup(b, B, Pb); for (i = 0; i < N; i++) { int t = a[i] - b[i]; if (t > 0) sa += a[i] + b[i]; else if (t < 0) sb += a[i] + b[i]; } if (sa > sb) ans++; } printf("%.5lf\n", ((double)ans) / LOOP); return 0; }