【HDU5159】【BestCoderRound26.1002】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 rounds.
Assume that the score of the j-th card he picks is
Sj
. You are expected to calculate the expectation of the sum of the different score he picks.

Input

Multi test cases,the first line of the input is a number T which indicates the number of test cases.

In the next T lines, every line contain x,b separated by exactly one space.

[Technique specification]

All numbers are integers.

1<=T<=500000

1<=x<=100000

1<=b<=5

Output

Each case occupies one line. The output format is Case #id: ans, here id is the data number which starts from 1,ans is the expectation, accurate to 3 decimal places.

See the sample for more details.

Sample Input

2
2 3
3 3

Sample Output

Case #1: 2.625
Case #2: 4.222

Hint

For the first case, all possible combinations BieBie can pick are (1, 1, 1),(1,1,2),(1,2,1),(1,2,2),(2,1,1),(2,1,2),(2,2,1),(2,2,2)
For (1,1,1),there is only one kind number i.e. 1, so the sum of different score is 1.
However, for (1,2,1), there are two kind numbers i.e. 1 and 2, so the sum of different score is 1+2=3.
So the sums of different score to corresponding combination are 1,3,3,3,3,3,3,2
So the expectation is (1+3+3+3+3+3+3+2)/8=2.625

翻译题目

问题描述

桌子上有a张牌,每张牌从1到a编号,编号为i(1<=i<=a)的牌上面标记着分数i , 每次从这a张牌中随机抽出一张牌,然后放回,执行b次操作,记第j次取出的牌上面分数是 Sj , 问b次操作后不同种类分数之和的期望是多少。

输入描述

多组数据,第一输入数据组数T ,接下来T行,每行两个整数a,b以空格分开

[参数说明]
所有输入均为整数
1<=T<=500000
1<=a<=100000
1<=b<=5

输出描述

输出答案占一行,输出格式为 Case #x: ans, x是数据编号从1开始,ans是答案,精确到小数点后3位。
看样例可以得到更多信息。

输入样例

2
2 3
3 3

输出样例

Case #1: 2.625
Case #2: 4.222

提示:
对于第一组数据所有牌型的组合为(1, 1, 1),(1,1,2),(1,2,1),(1,2,2),(2,1,1),(2,1,2),(2,2,1),(2,2,2)
对于(1,1,1)这个组合,他只有一种数字,所以不同数字之和为1
而对于(1,2,1)有两种不同的数字,即1和2,所以不同数字之和是3。
所以对应组合的不同数字之和为1,3,3,3,3,3,3,2
所以期望为(1+3+3+3+3+3+3+2)/8=2.625

数学期望题。

虽然之前学过期望,学过期望的线性性质,会一点概率,但是这次比赛做这个题来看发现自己其实还是学的不到功夫啊。。。

看到题解的一瞬间就明白了

但是比赛过程中就是没想出来

哎。。。。

设Xi代表分数为i的牌在b次操作中是否被选到,Xi=1为选到,Xi=0为未选到
那么期望EX=1*X1+2*X2+3*X3+…+x*Xx
Xi在b次中被选到的概率是1-(1-1/x)^b
那么E(Xi)= 1-(1-1/x)^b
那么EX=1*E(X1)+2*E(X2)+3*E(X3)+…+x*E(Xx)=(1+x)*x/2*(1-(1-1/x)^b)————赛后题解

其实明明能看懂,能明白的QAQ

这么蛋疼的题

代码就只有这么短= =

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	int T,a,b;
	scanf("%d",&T);
	for (int i=1;i<=T;i++)
	{
		scanf("%d%d",&a,&b);
		double a1=1-pow(1-1.0/a,b);
		double x=a;
		double ans=x*(x+1)/2*a1;
		printf("Case #%d: %.3lf\n",i,ans);
	}
}
时间: 2024-10-07 04:17:24

【HDU5159】【BestCoderRound26.1002】Card的相关文章

【2014 Multi-University Training Contest 3 1002】/【HDU 4888】 Redraw Beautiful Drawings

不容易啊,终于可以补第二个题了!! 顺便说一句:模版写残了就不要怪出题人啊 ~ (这残废模版研究了好长时间才找出错) 题目大意: 有一个n*m的矩阵,每一个格子里都将有一个数.给你每一行数字之和和每一列数字之和.求每一个位置能填0~k之间的哪个数.如果有多种可能输出"Not Unique",如果没有解输出"Impossible",如果一组解则将其输出. 解题思路: 最大流: 不可能的条件:是行之和和列之和不想等或者建图后的最大流与他们不想等. 多组的条件是:在最大流

【LightOJ 1002】 Country Roads

[LightOJ 1002] Country Roads ...又一个另类OJ...最长路 贴个SPFA的 #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <queue> #include <set> using namespace std; int mp[555][555]; int dis[555]; bool

大数A+B 【杭电-1002】 附题

/* A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 209912    Accepted Submission(s): 40404 Problem Description I have a very simple problem for you. Given two integers A and B,

【浅墨Unity3D Shader编程】之三 光之城堡篇:子着色器、通道与标签的写法 &amp; 纹理混合

本系列文章由@浅墨_毛星云 出品,转载请注明出处. 文章链接:http://blog.csdn.net/poem_qianmo/article/details/41175585 作者:毛星云(浅墨)    微博:http://weibo.com/u/1723155442 邮箱: [email protected] 本文介绍了Unity中子着色器.通道和标签相关的详细概念与写法,以及纹理的设置方法,基本的纹理混合写法,写了5个Shader作为本文Shader讲解的实战内容,最后创建了一个梦幻的光之

HDU2121 Ice_cream’s world II 【最小树形图】+【不定根】

Ice_cream's world II Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2744    Accepted Submission(s): 630 Problem Description After awarded lands to ACMers, the queen want to choose a city be he

POJ2886 Who Gets the Most Candies? 【线段树】+【单点更新】+【模拟】+【反素数】

Who Gets the Most Candies? Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 9416   Accepted: 2868 Case Time Limit: 2000MS Description N children are sitting in a circle to play a game. The children are numbered from 1 to N in clockwise o

【来写个2048吧】—— 后期优化及源代码

卡片里的数字假设越来越大则会超过卡片,这样看起来不好看,所以我们要推断数字的位数然后设置合适的大小. 在Card.cpp的setNumber()中增加例如以下代码 //设置数字大小 if ( num >= 0) { labelCardNumber->setFontSize (100); } if ( num >= 16) { labelCardNumber->setFontSize (90); } if ( num >= 128) { labelCardNumber->

POJ2155 Matrix 【二维树状数组】+【段更新点查询】

Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 17766   Accepted: 6674 Description Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the i-th row and j-th column. Initially we have A[i, j] = 0 (1

【黑金原创教程】【FPGA那些事儿-驱动篇I 】连载导读

前言: 无数昼夜的来回轮替以后,这本<驱动篇I>终于编辑完毕了,笔者真的感动到连鼻涕也流下来.所谓驱动就是认识硬件,还有前期建模.虽然<驱动篇I>的硬件都是我们熟悉的老友记,例如UART,VGA等,但是<驱动篇I>贵就贵在建模技巧的升华,亦即低级建模II. 话说低级建模II,读过<建模篇>的朋友多少也会面熟几分,因为它是低级建模的进化形态.许久以前,笔者就有点燃低级建模II的念头,但是懒惰的性格让笔者别扭许久.某天,老大忽然说道:"让咱们大干一场吧