hdu 5159(概率)

题目链接:

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;
}

 

posted @ 2016-07-16 16:40  樱花庄的龙之介大人  阅读(196)  评论(0)    收藏  举报