HDU 5159 Card( 计数 期望 )
Card
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 191 Accepted Submission(s): 52
Special Judge
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
See the sample for more details.
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

设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)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <algorithm>
using namespace std;
#define root 1,n,1
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define lr rt<<1
#define rr rt<<1|1
typedef long long LL;
typedef pair<int,int>pii;
#define X first
#define Y second
const int oo = 1e9+;
const double PI = acos(-1.0);
const double eps = 1e- ;
const int N = ;
double n ;int m ;
void Run() {
scanf("%lf%d",&n,&m);
double avg = ( 1.0 + n ) * n / 2.0 * pow( 1.0 / n , (double) m ) , res = ;
for( int i = ; i < m ; ++i ) {
res += avg * pow( n - 1.0 , (double)i )*pow( (double)n, m-i-1.0 );
}
printf("%.3lf\n",res);
}
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif // LOCAL
ios::sync_with_stdio(false);
int _ , cas = ; scanf("%d",&_);
while( _-- ){
printf("Case #%d: ",cas++); Run();
}
}
HDU 5159 Card( 计数 期望 )的更多相关文章
- hdu 5159 Card (期望)
Problem Description There are x cards on the desk, they are numbered from 1 to x. The score of the c ...
- HDU 5159 Card (概率求期望)
B - Card Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Sta ...
- HDU 4336 Card Collector 期望dp+状压
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4336 Card Collector Time Limit: 2000/1000 MS (Java/O ...
- hdu 4336 Card Collector(期望 dp 状态压缩)
Problem Description In your childhood, people in the famous novel Water Margin, you will win an amaz ...
- HDU 5159 Card
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5159 题解: 考虑没一个数的贡献,一个数一次都不出现的次数是(x-1)^b,而总的排列次数是x^b, ...
- HDU 4336 Card Collector (期望DP+状态压缩 或者 状态压缩+容斥)
题意:有N(1<=N<=20)张卡片,每包中含有这些卡片的概率,每包至多一张卡片,可能没有卡片.求需要买多少包才能拿到所以的N张卡片,求次数的期望. 析:期望DP,是很容易看出来的,然后由 ...
- hdu 5868 Polya计数
Different Circle Permutation Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 262144/262144 K ...
- hdu 2865 Polya计数+(矩阵 or 找规律 求C)
Birthday Toy Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- Card Collector(期望+min-max容斥)
Card Collector(期望+min-max容斥) Card Collector woc居然在毫不知情的情况下写出一个min-max容斥 题意 买一包方便面有几率附赠一张卡,有\(n\)种卡,每 ...
随机推荐
- 攻防世界--no-strings-attached
测试文件:https://adworld.xctf.org.cn/media/task/attachments/5d4117b968684b9483d0d4464e0a6fea 这道题要使用到gdb文 ...
- Fabric管理组件的使用
Fabric的官方网站: http://www.fabfile.org 帮助文档: https://fabric-chs.readthedocs.io/zh_CN/chs/tutorial.html ...
- 如何在Ubuntu 18.04上安装Apache Web服务器
一. apt库安装 1.在终端输入更新检查命令,sudo apt-get update 2. 在更新完成后(如果不想检查更新,也可直接输入此步)输入:sudo apt-get install apac ...
- 爬虫技术:cookies池的维护
一:为什么要维护cookie 1.登录才能爬取内容 2.爬取频繁会被封号. 3.需要维护多个账号的cookie,实现大规模抓取 二:cookies的要求 1.自动登录更新 2.定期筛选验证 3.提供外 ...
- max_length 属性
错误:漏掉了 max_length 属性 ERRORS:users.UserProfile.image: (fields.E210) Cannot use ImageField because Pi ...
- Kafka数据如何同步至MaxCompute之实践讲解
摘要:本次分享主要介绍Kafka产品的原理和使用方式,以及同步数据到MaxCompute的参数介绍.独享集成资源组与自定义资源组的使用背景和配置方式.Kafka同步数据到MaxCompute的开发到生 ...
- JS中数据结构之图
图由边的集合及顶点的集合组成.边是有方向的是有序图(有向图),否则就是无序图(无向图).图中的一系列顶点构成路径,路径中所有的顶点都由边连接.路径的长度用路径中第一个顶点到最后一个顶点之间边的数量表示 ...
- BZOJ 2982: combination Lucas模板题
Code: #include<bits/stdc++.h> #define ll long long #define maxn 1000003 using namespace std; c ...
- 【Linux】关闭selinux
vi /etc/selinux/config 将SELINUX=enforcing改为SELINUX=disabled 设置后需要重启才能生效
- Oracle or Question Solve(一)
Oracle查看版本命令:select * from v$version; ORACLE_BASE和ORACLE_HOME路径查看su - oracleecho $ORACLE_BASEecho $O ...