编程啦 1269 投骰子(求期望)

http://www.bianchengla.com/course/cpp/practise/problem?id=1269

可以计算出投一次可得的分数是1*1/6 + 2 * 1/6 + 3 * 1/6 + 4 * 1/6 + 5 * 1/6 + 6 * 1/6 = 3.5 ;然后n次的期望就是3.5*n;

代码:

View Code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <queue>
#include <math.h>
#include <map>
#define  N 100003
using namespace std ;

int d[N] ;

int main()
{
    int cas , p , n ;

    cin>>cas ;
    while( cas-- )
    {
        cin>>p>>n ;
        double s = 3.5 * p * n ;
        printf ( "%.2lf\n" , s ) ;
    }
    return 0 ;
}

 

posted @ 2013-02-20 15:11  Misty_1  阅读(272)  评论(0编辑  收藏  举报