No.133 Card Game
タグ : / 解いたユーザー数 647
作問者 :
nmnmnmnmnmnmnm
Problem Statement
A-kun and B-kun like card games.
The card game is played with 2*N cards, each with one of the numbers from 1 to 2*N written on it, one number per card.
A-kun and B-kun are each dealt N cards.
The game is simple.
Each player freely plays one card, and the player with the larger number wins that match.
A card that has been played once in a match cannot be used again.
A total of N matches are played, and the player with more match wins wins the game.
If A-kun and B-kun have the same number of wins, the game is a draw.
The cards have already been dealt.
Compute the probability that A-kun wins the game when the N matches are over.
Both players play their cards at random, without any strategy.
Input
$N$
$A_0\ A_1\ \dots\ A_{N-1}$
$B_0\ B_1\ \dots\ B_{N-1}$
$N$ is an integer with $1\le N \le 4$.
$A_0,A_1,...,A_{N-1}$ and $B_0,B_1,...,B_{N-1}$ contain the numbers from $1$ to $2*N$.
There are no duplicate numbers among $A_0,A_1,...,A_{N-1}$ and $B_0,B_1,...,B_{N-1}$.
Output
Output the probability that A-kun wins on one line. An error of up to ±0.01 is allowed.
Do not forget the newline at the end.
Sample
Sample 1
Input
2 2 4 1 3
Output
0.5
A-kun is dealt the cards 2 and 4. B-kun is dealt the cards 1 and 3.
There are 2 matches, with 2 ways for A-kun to play his cards and 2 ways for B-kun to play his, so there are 4 outcomes in total.
A-kun wins in 2 of them, so the probability is 2/4=0.5.
Sample 2
Input
2 3 4 1 2
Output
1
A-kun wins no matter what.
Sample 3
Input
1 1 2
Output
0
A-kun cannot win no matter what.
Sample 4
Input
3 6 2 3 1 5 4
Output
0.666667
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。