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 再对每张牌乘上牌面的值即是期望.
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; }
相关文章推荐
- BZOJ 3224: Tyvj 1728 普通平衡树 treap
- Application tried to present a nil modal view controller on target “Current View Controller”解决方案
- 云直播系统架构与实施
- 大话设计模式:工厂模式
- jquery 常用的tabs效果代码
- Winform跨程序发送、接收消息
- EnumSet抽象类源码解析
- Codeforces Round #241 (Div. 2) B dp
- C语言 程序 位运算
- HTTP的请求方法OPTIONS
- Linux进程间通讯(IPC)------FIFO
- 动态规划——最长公共子序列问题(LCS)
- Centos6服务器部署JavaWeb项目(tomcat6+jdk6)
- Codeforces 696A. Lorenzo Von Matterhorn(map离散化)
- 建立ROS的代码环境
- 【Spring 2】spring的属性注入形式
- 源码分析-java-AbstractCollection
- jQuery之动画效果
- Java设计模式—中介者模式
- Fragment的setUserVisibleHint方法实现懒加载