标签:opened isp closed can include lan log play 1.0
题意: 2^k个人,你排名第r, 问你期望能赢的次数.
至少赢 i 次的概率是 C(2^i-1, 2^k-r) / C(2^i-1, 2^k-1) ,化简一下
1 #include <bits/stdc++.h> 2 using namespace std; 3 int k, r; 4 5 int main() { 6 scanf("%d %d", &k, &r); 7 int m = (1<<k) - r; 8 double ans = 0; 9 int i; 10 for(i = 1; (1<<i)-1 <= m; i++){ 11 double p = 1.0; 12 // int a = (1<<k) - (1<<i) + 2 - r; 13 //int c = (1<<k) - r + 1; 14 int a = (1<<k) - 1; 15 int c = (1<<k) - r; 16 for(int j = 0; j <(1<<i)-1 ; j++) { 17 p = p*c/a; 18 a--; 19 c--; 20 } 21 ans += p; 22 } 23 printf("%.5lf\n", ans); 24 }
标签:opened isp closed can include lan log play 1.0
原文地址:http://www.cnblogs.com/yijiull/p/7624266.html