module main; // https://mayokoex.hatenablog.com/entry/2015/03/27/142127 より // モンテカルロ法 import std; alias P = Tuple!(int, int); immutable repeatCount = 10_000; int N; int[] A, B; uint PA, PB; bool win() { int aPoint = 0, bPoint = 0; auto aRest = [true].replicate(N), bRest = [true].replicate(N); foreach (i; 0 .. N - 1) { P[] a, b; foreach (j; 0 .. N) { if (aRest[j]) a ~= P(A[j], j); if (bRest[j]) b ~= P(B[j], j); } a.sort; b.sort; int aCard, bCard; if (uniform!"[]"(0, 1000) <= PA) { aCard = a[0][0]; aRest[a[0][1]] = false; } else { int tmp = uniform!"[]"(1, N - i - 1); aCard = a[tmp][0]; aRest[a[tmp][1]] = false; } if (uniform!"[]"(0, 1000) <= PB) { bCard = b[0][0]; bRest[b[0][1]] = false; } else { int tmp = uniform!"[]"(1, N - i - 1); bCard = b[tmp][0]; bRest[b[tmp][1]] = false; } if (aCard > bCard) aPoint += aCard + bCard; else bPoint += aCard + bCard; } int a, b; foreach (i; 0 .. N) { if (aRest[i]) a = A[i]; if (bRest[i]) b = B[i]; } if (a > b) aPoint += a + b; else bPoint += a + b; return aPoint > bPoint; } void main() { // 入力 double[2] P; readln.chomp.formattedRead("%d %f %f", N, P[0], P[1]); PA = round(P[0] * 1000).to!uint; PB = round(P[1] * 1000).to!uint; A = readln.split.to!(int[]); B = readln.split.to!(int[]); // 答えの計算 int winNum = 0; foreach (_; 0 .. repeatCount) { winNum += win(); } double ans = winNum; ans /= repeatCount; // 答えの出力 writefln("%.10f", ans); }