Card Game (First Edition) FZU - 2264 Card Game (Second Edition) FZU - 2265 (数学期望)

Fat brother and Maze are playing a kind of special (hentai) game with some cards. There are N*2 cards in this game for the players to use, this is the card deck. The game goes for N rounds and in each round, Fat Brother would draw one card from the remaining card deck randomly and then Maze would draw one card from the remaining card deck randomly. Then they compare for the integers which is written on these two 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 one line with N*2 integers, which indicate the integers in these cards.

All the integers are positive and no morethan 10000000.

Output

For each case, output the case number first, and then output the expect number of the victory points Fat Brother could get in this game. The answer should be rounded to 2 digits after the decimal point.

Sample Input
2
1
1 2
2
1 2 3 4
Sample Output
Case 1: 0.50
Case 2: 1.00

题意:输入t,下面有t组数据,每组数据第一行一个数n,表示有n轮比赛,下面有 2*n 的数,从第一轮比赛开始,每一轮两人一次从剩下的牌中各抽取一张,比较点数,谁大谁赢,获得一分,求A最后获得分数的期数;

下面给你期望的定义:

概率论和统计学中,数学期望(mean)(或均值,亦简称期望)是试验中每次可能结果的概率乘以其结果的总和,是最基本的数学特征之一。它反映随机变量平均取值的大小。

1. 在17世纪,有一个赌徒向法国著名数学家帕斯卡挑战,给他出了一道题目:甲乙两个人赌博,他们两人获胜的机率相等,比赛规则是先胜三局者为赢家,赢家可以获得100法郎的奖励。当比赛进行到第四局的时候,甲胜了两局,乙胜了一局,这时由于某些原因中止了比赛,那么如何分配这100法郎才比较公平?

用概率论的知识,不难得知,甲获胜的可能性大,甲赢了第四局,或输掉了第四局却赢了第五局,概率为1/2+(1/2)*(1/2)=3/4。分析乙获胜的可能性,乙赢了第四局和第五局,概率为(1/2)*(1/2)=1/4。因此由此引出了甲的期望所得值为100*3/4=75法郎,乙的期望所得值为25法郎。这个故事里出现了“期望”这个词,数学期望由此而来。  [1]  22
2.离散型

      

某城市有10万个家庭,没有孩子的家庭有1000个,有一个孩子的家庭有9万个,有两个孩子的家庭有6000个,有3个孩子的家庭有3000个。
则此城市中任一个家庭中孩子的数目是一个随机变量,记为X。它可取值0,1,2,3。
其中,X取0的概率为0.01,取1的概率为0.9,取2的概率为0.06,取3的概率为0.03。
则,它的数学期望
   
,即此城市一个家庭平均有小孩1.11个。

求 n轮之后 获得分数的期望  分数的期望等于 赢的概率 * 本轮获得的分数

给出结论:两个从n的数中依次选出一个数,比较大小,两人赢得概率相等都是 0.5;

推:

当n = 2时, 1,2   A的赢的为0.5;

当n = 3时 1,2,3  A选每个数的概率都是相等的 都是1/3, 选1 赢的概率为0,选2赢的概率为 1/2 选3赢得概率为 1,综上述三种情况 1/3*0+1/3*1/2+1/3*1 = 0.5;

当 n = 4时,A赢的概率也是0.5;

综上知:每轮赢得概率都是 0,5;

代码:

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
	int i,j;
	int t,n;
	scanf("%d",&t);
	j = 1;
	while(t--)
	{
		scanf("%d",&n);
		int x;
		for(i = 0;i<2*n;i++)
			scanf("%d",&x);
		printf("Case %d: %.2f\n",j++,(double)n*0.5);
	}
	return 0;
} 

Card Game (Second Edition)  FZU - 2265     

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

题意:t组数据,n表示有 A有n张牌,B有n张牌,每一轮中,A从A中的剩余牌中 取出一张,B从B中剩余牌中取出一张,两张牌比较大小,大的获胜的1分,求 n轮后,A获胜的数学期望;

思路:第一轮 A赢的概率,容易求,但是以后下面那n-1轮 A赢得概率怎么求呢? 大家可以想想, A抽A中的数时,不管怎么在第几轮抽到,被抽到的概率都是1/n (比如在第二轮抽到,那么是在第一轮没有抽的前提下抽到的,在第 i 轮被抽到,是在前i-1轮没有抽到的前提下抽到的,你算一算就知道为啥概率都是1/n了),B也一样,所以 后n-1 轮赢的概率和 第一轮赢的概率是相同的;

代码:

#include<stdio.h> 
#include<string.h>
#include<algorithm>
using namespace std;
#define Max 10010
int a[Max],b[Max];
int main()
{
	int i,j,t,tt=1;
	scanf("%d",&t);
	while(t--)
	{
		int n;
		scanf("%d",&n);
		for(i = 0;i<n;i++)
			scanf("%d",&a[i]);
		for(j = 0;j<n;j++)
			scanf("%d",&b[j]);
		sort(a,a+n);
		sort(b,b+n);
		double ans = 0;
		for(i = 0;i<n;i++)
		{
			ans += lower_bound(b,b+n,a[i]) - b;
		}
		printf("Case %d: %.2f\n",tt++,ans/n);
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值