zoukankan      html  css  js  c++  java
  • (寒假CF3)坑坑坑

    题意 :求期望

    题解 :找规律,列举几个,然后找到规律。

    坑点:要简化,不简化数字一大就wa了

    Sample Input
    Input
    6 1
    Output
    3.500000000000
    Input
    6 3
    Output
    4.958333333333
    Input
    2 2
    Output
    1.750000000000
    Hint
    Consider the third test example. If you've made two tosses:

    You can get 1 in the first toss, and 2 in the second. Maximum equals to 2.
    You can get 1 in the first toss, and 1 in the second. Maximum equals to 1.
    You can get 2 in the first toss, and 1 in the second. Maximum equals to 2.
    You can get 2 in the first toss, and 2 in the second. Maximum equals to 2.
    The probability of each outcome is 0.25, that is expectation equals to:


    You can read about expectation using the following link: http://en.wikipedia.org/wiki/Expected_value

     1 #include<stdio.h>
     2 #include<math.h>
     3 int main()
     4 {
     5     int m,n,times,i,j,a;
     6     float sum;
     7     while(~scanf("%d %d",&m,&n))
     8     {
     9         sum=0.0;
    10 
    11                 for(j=1;j<=m;j++)
    12             {
    13                 sum+=(pow(1.0*j/m,n)-pow(1.0*(j-1)/m,n))*j;
    14             }
    15         printf("%.12lf
    ",sum);
    16     }
    17     return 0;
    18 }
  • 相关阅读:
    冒泡排序-用函数写
    c#语言基础
    c#小知识点
    令人头疼的冒泡排序
    字符串 与函数
    数组 冒泡排序 打印菱形 随机生成不同的数
    if语句练习
    运算符练习
    类型转换
    C#初学
  • 原文地址:https://www.cnblogs.com/awsent/p/4270983.html
Copyright © 2011-2022 走看看