hdu 5159 Card(数学)
来源:互联网 发布:vm虚拟机网络连接 编辑:程序博客网 时间:2024/05/28 17:06
Card
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 821 Accepted Submission(s): 337
Special Judge
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
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.
See the sample for more details.
Sample Input
22 33 3
Sample Output
Case #1: 2.625Case #2: 4.222HintFor 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,2So the expectation is (1+3+3+3+3+3+3+2)/8=2.625
思路:一开始没想出来...真是太菜了。
看见这种求所有数字中取m个数字之和的所有可能性之和就应该想到1~n这n个数字是被“平等对待”的
也就是说,当我们得到所有的可能性之和的时候,1~n中的所有数字被加的次数都应该是相等的
而这个被加的次数就是n的m次方-(n-1)的m次方 前者是所有的可能性,后者是不取某一个数的所有可能性(也就是说不取某一个数的所有的区间之和)
所以最终结果是(n*(n+1)/2)*(n(m)-(n-1)(m))/n(m)
n(m)表示n的m次方
代码:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>using namespace std;int main(){ double x,b; int T; scanf("%d",&T); for(int t=1;t<=T;t++) { scanf("%lf %lf",&x,&b); double sum=x*(x+1)/2; sum*=pow(x,b)-pow(x-1,b); double sum1=pow(x,b); printf("Case #%d: %.3lf\n",t,sum/sum1); } return 0;}
0 0
- hdu 5159 Card(数学)
- HDU 5159 Card(数学期望)
- HDU 5159 Card (组合数学)
- HDU 4350 Card(数学)
- HDU 4336 Card Collector 数学期望(容斥原理)
- hdu 4366 Card Collector(组合数学:容斥定理)
- (数学,概率论)Card Trick
- HDU 5159 Card (概率DP)
- HDU 6205 card card card(展开字符串思想+思维)
- HDU 6205 card card card(尺取法)
- hdu 6205 card card card(最大子段和)
- HDU-6052 card card card(尺取法)
- hdu 6205 card card card (尺取法)
- hdu 6205 card card card
- HDU 6205:card card card
- HDU 6205 card card card
- hdu 6205 card card card
- card card card HDU-6205
- appcan开发经验总结
- Guava使用总结
- spring+mybatis配置多数据源
- ACE开发环境搭建
- android笔记
- hdu 5159 Card(数学)
- poj 2031(空间 最短路 prime)
- Linux下获取用户主目录的方法分享
- 10 个很有用的高级 Git 命令
- 通过Docker搭建Mysql容器+Tomcat容器连接环境
- 关于Sublime text 2中Emmet的安装 _html:xt无效
- DOM中元素节点、属性节点、文本节点的理解
- EventBus3.0源码解析
- Linux Ubuntu14 用户密码设置