FZUOJ 2265 Card Game (Second Edition)
題目鏈接:http://acm.fzu.edu.cn/problem.php?pid=2265
第七屆福建省賽重現賽D題,概率計算不過挺有技巧的,問了acdart兄才恍然大悟(分明看了好長時間。。。)
acdart原話:
b 從小到大排序, a對應有n!中排列,其中a[i]對於某個b[j]是有(n-1)!都是對應的(因為a[i]只能對應n個b中),而a[i]對應b[j]的值是一定的,可以直接計算出每個a[i]在這n!中方案中的貢獻值,所有a[i]然後相加除以n!(可以把n-1!去掉,最後就是除以n了)。 就是說每個a[i]都會有n*(n-1)!種對應情況,然後只要算出n種情況裏面哪幾個貢獻出了1分,最後n個相加除以n!然後約分就是期望值了。 代碼:1const int maxn = 10010; 2 int n, a[maxn], b[maxn]; 3 4 int main(){ 5 int t; 6 scanf("%d", &t); 7 for(int ii = 1; ii <= t; ii++){ 8 scanf("%d", &n); 9 for(int i = 0; i < n; i++){ 10 scanf("%d", &a[i]); 11 } 12 for(int i = 0; i < n; i++){ 13 scanf("%d", &b[i]); 14 } 15 sort(b, b + n); 16 int ans = 0; 17 for(int i = 0; i < n; i++){ 18 ans += upper_bound(b, b + n, a[i]) - b; 19 } 20 printf("Case %d: %.2f\n", ii, 1.0 * ans / n); 21 } 22 }
題目:
Accept: 30 Submit: 68
Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem Description
Fat brother and Maze are playing a kind of special (hentai) game with some cards. In this game, every player gets N cards at first and these are their own card deck. The game goes for N rounds and in each round, Fat Brother and Maze would draw one card from their own remaining card deck randomly and compare for the integer which is written on the cards. The player with the higher number wins this round and score 1 victory point. And then these two cards are removed from the game such that they would not appear in the later rounds. As we all know, Fat Brother is very clever, so he would like to know the expect number of the victory points he could get if he knows all the integers written in these cards.
Note that the integers written on these N*2 cards are pair wise distinct. At the beginning of this game, each player has 0 victory point.
Input
The first line of the data is an integer T (1 <= T <= 100), which is the number of the text cases.
Then T cases follow, each case contains an integer N (1 <=N<=10000) which described before. Then follow two lines with N integers each. The first N integers indicate Fat Brother’s cards and the second N integers indicate Maze’s cards.
All the integers are positive and no more than 10000000.
Output
For each case, output the case number first, and then output the expect number of victory points Fat Brother would gets in this game. The answer should be rounded to 2 digits after the decimal point.
Sample Input
2 1 1 2 2 1 3 2 4Sample Output
Case 1: 0.00 Case 2: 0.50Source
第七屆福建省大學生程序設計競賽-重現賽(感謝承辦方閩江學院)FZUOJ 2265 Card Game (Second Edition)