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!然后约分就是期望值了。
代码:
 1 const 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
", ii, 1.0 * ans / n);
21     }
22 } 

题目:

Problem 2265 Card Game (Second Edition)

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 4

 Sample Output

Case 1: 0.00 Case 2: 0.50

 Source

第七届福建省大学生程序设计竞赛-重现赛(感谢承办方闽江学院)
原文地址:https://www.cnblogs.com/bolderic/p/7208647.html