zoukankan      html  css  js  c++  java
  • ZOJ Monthly, October 2011 Prolem C

      被这套题暴虐。。。高中学的东西基本还给老师了。想了半天不知道什么是数学期望,我晕啊!!今天问师兄,答曰:数学期望就是概率的倒数。再回头想想高中残留的那点模糊的记忆,真想一头撞死!

    思路:

      共n个生物,从中取出两个来,共有的情况数是,设当前有i个吸血鬼,则有n-i个人类。所以吸血鬼和人类相遇的情况数为* ,所以本次有人类变成吸血鬼的概率为

     P = **p / ,所以,本次的数学期望为1/P;

    Code:

    #include <iostream>
    #include <cstdio>

    using namespace std;

    int main() {
    //freopen("data.in", "r", stdin);

    int T, i;
    double p, ans, c, n;
    scanf("%d", &T);
    while(T--) {
    scanf("%lf%lf", &n, &p);
    c = n*(n-1)/2;
    for(ans = 0, i = 1; i < n; i++) {
    ans += c/((n-i)*i*p);
    }
    printf("%.3lf\n", ans);
    }
    return 0;
    }



  • 相关阅读:
    函数的定义
    函数加载的过程
    js中的return
    快速排序
    冒泡排序
    数组的案例
    正睿暑期培训day3考试
    bzoj2115 Xor
    luogu4570 元素
    bzoj4827 Hnoi2017 礼物
  • 原文地址:https://www.cnblogs.com/vongang/p/2230717.html
Copyright © 2011-2022 走看看