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\n", 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

第七届福建省大学生程序设计竞赛-重现赛(感谢承办方闽江学院)

时间: 2025-01-05 05:47:38

FZUOJ 2265 Card Game (Second Edition)的相关文章

[it-ebooks]电子书列表

#### it-ebooks电子书质量不错,但搜索功能不是很好 #### 格式说明  [ ]中为年份      ||  前后是标题和副标题  #### [2014]: Learning Objective-C by Developing iPhone Games || Leverage Xcode and Objective-C to develop iPhone games http://it-ebooks.info/book/3544/ Learning Web App Developmen

(转) [it-ebooks]电子书列表

[it-ebooks]电子书列表 [2014]: Learning Objective-C by Developing iPhone Games || Leverage Xcode and Objective-C to develop iPhone games http://it-ebooks.info/book/3544/Learning Web App Development || Build Quickly with Proven JavaScript Techniques http://

sdio card休眠处理 sdio card removed解决办法

最近调试几款sdio card suspend时都会出现sdio card removed,之后 要么死机要么模块不能正常工作,根本原因也就是休眠没有处理好. 昨天在博通网卡上终于找到了解决方法. 1:host端需要设置nonremovable,软件设置:mmc->caps |= MMC_CAP_NONREMOVABLE; 2:host端需要设置keep power,在sdio card suspend时 软件设 置:host->pm_flags | = MMC_PM_KEEP_POWER:

UESTC 31 饭卡(Card) --背包问题

背包问题. 思路:如果m<5,此时也不能消费,所以此时答案为m m>=5: 求出背包容量为m-5,买前n-1样便宜的菜(排个序)的最大价值(即最大消费,即消费完后剩余值最接近5)最后减去最大的那个菜的价格,就得到最小的余额. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using n

hdu 4336 Card Collector

Card Collector http://acm.hdu.edu.cn/showproblem.php?pid=4336 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Special Judge Problem Description In your childhood, do you crazy for collecting the beautiful cards in

Using Android Phone to recover SD card formatted with DD command under linux

1. Formatted a sd card with dd command under linux 2.insert the sd card into an android phone,certainly the card is not find and used.. 3 reset the android phone with format sd card option. 4.the sd card is ok!

Secrets To Getting Amazon gift card codes To Complete Tasks Quickly And Efficiently

Amazon gift card are not as easy to get if you do not know how to complet a survey . Amazon gift card are difficult and as hard to combact with the survey . So please do not hurry you should try the new method to get free amazon gift card codes . For

Identity Card(水题)

Identity Card Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2696    Accepted Submission(s): 1048 Problem Description Do you own an ID card?You must have a identity card number in your family'

hdu 5159 Card (期望)

Problem Description There are x cards on the desk, they are numbered from 1 to x. The score of the card which is numbered i(1<=i<=x) is i. Every round BieBie picks one card out of the x cards,then puts it back. He does the same operation for b round