标签:
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 191 Accepted Submission(s): 52
Special Judge
设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+7; const double PI = acos(-1.0); const double eps = 1e-6 ; const int N = 100010; 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 = 0 ; for( int i = 0 ; 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 = 1 ; scanf("%d",&_); while( _-- ){ printf("Case #%d: ",cas++); Run(); } }
标签:
原文地址:http://www.cnblogs.com/hlmark/p/4215835.html