您的位置:首页 > 其它

hdu 5159(概率)

2016-07-16 16:40 288 查看
题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=5159

题解:假设在 x 张牌中选b张牌,那么有 x^b 种选法,如果在 (x-1) 张牌中选 b 张牌,那么有 (x-1)^b 种选法,所以第 i 张牌出现的概率是 (x^b-(x-1)^b)/x^b 再对每张牌乘上牌面的值即是期望.

#include<stdio.h>
#include<iostream>
#include<string.h>
#include <stdlib.h>
#include<math.h>
#include<algorithm>
#include <queue>
using namespace std;
typedef unsigned long long LL;
int main()
{
int tcase;
scanf("%d",&tcase);
int t =1;
while(tcase--){
int x,b;
scanf("%d%d",&x,&b);
double a = 1-pow(1-1.0/x,b);
printf("Case #%d: %.3lf\n",t++,a*(x+1)*x/2);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: