問題一覧 > 通常問題

No.133 Card Game

レベル : / AI推定難易度 : 189 / 実行時間制限 : 1ケース 5.000秒 / メモリ制限 : 512 MB / 小数誤差許容問題 絶対誤差または相対誤差が $10^{-2}$ 以下。ただし、ジャッジ側の都合で500桁未満にしてください
タグ : (AC するまで非表示) / 解いたユーザー数 647
作問者 : nmnmnmnmnmnmnm
お気に入りにしたユーザー ProblemId : 199 / 自分の提出
問題文最終更新日: 2026-06-25 18:39:44
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 80 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。