zoukankan      html  css  js  c++  java
  • D. Ilya and Escalator

    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Ilya got tired of sports programming, left university and got a job in the subway. He was given the task to determine the escalator load factor.

    Let's assume that n people stand in the queue for the escalator. At each second one of the two following possibilities takes place: either the first person in the queue enters the escalator with probability p, or the first person in the queue doesn't move with probability (1 - p), paralyzed by his fear of escalators and making the whole queue wait behind him.

    Formally speaking, the i-th person in the queue cannot enter the escalator until people with indices from 1 to i - 1 inclusive enter it. In one second only one person can enter the escalator. The escalator is infinite, so if a person enters it, he never leaves it, that is he will be standing on the escalator at any following second. Ilya needs to count the expected value of the number of people standing on the escalator after t seconds.

    Your task is to help him solve this complicated task.

    Input

    The first line of the input contains three numbers n, p, t (1 ≤ n, t ≤ 2000, 0 ≤ p ≤ 1). Numbers n and t are integers, number p is real, given with exactly two digits after the decimal point.

    Output

    Print a single real number — the expected number of people who will be standing on the escalator after t seconds. The absolute or relative error mustn't exceed 10 - 6.

    Sample test(s)
    Input
    1 0.50 1
    Output
    0.5
    Input
    1 0.50 4
    Output
    0.9375
    Input
    4 0.20 2
    Output
    0.4

    题目抽象:n个人排队上电梯,排头每秒上去的概率为p,一共t秒,求t秒都电梯内人数的期望。

    思路:简单的概率dp,dp[i][j]表示第i秒电梯上有j个人的概率,最后累计一下期望

    
    
    
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstdlib>
     4 #include <cstring>
     5 #include <cmath>
     6 #include <algorithm>
     7 #include <string>
     8 #include <vector>
     9 #include <map>
    10 #include <set>
    11 #include <stack>
    12 #include <queue>
    13 #include <iomanip>
    14 using namespace std;
    15 const int INF=0x7fffffff;
    16 const double EXP=1e-8;
    17 const int MS=2005;
    18 const int mod=100000007;
    19 typedef long long LL;
    20 double dp[MS][MS];   
    21 //  dp[i][j]   在i second 的时间内 进入 了j个人的概率,  
    22 
    23 ///                dp[i-1][n-1]*p  
    24 //  dp[i][n]    
    25 //                dp[i-1][n]*1; 
    26 
    27 int main()
    28 {
    29     
    30     int n,t,i,j;
    31     double p,ans=0;
    32     memset(dp,0,sizeof(dp));
    33     dp[0][0]=1.0;
    34     cin>>n>>p>>t;
    35     for(i=0;i<t;i++)
    36     {
    37         for(j=0;j<n;j++)
    38         {
    39             dp[i+1][j+1]+=dp[i][j]*p;
    40             dp[i+1][j]+=dp[i][j]*(1-p); 
    41         }
    42         dp[i+1][n]+=dp[i][n];    
    43         //特别注意这里。 因为n特殊一点
    44         //                        dp[i][n-1]*p
    45         //       dp[i+1][n] 
    46         //                        dp[i][n]*p; 
    47     }
    48     for(i=1;i<=n;i++)
    49         ans+=i*dp[t][i];
    50     cout<<setiosflags(ios::fixed)<<setprecision(6)<<ans<<endl;
    51     return 0;
    52 }
  • 相关阅读:
    jquery笔记
    linux的日常经常使用的命令
    IDEA设置类注解和方法注解(详解)
    java读取项目或包下面的属性文件方法
    枚举类的使用
    将一个浮点数转化为人民币大写字符串
    简单五子棋实现
    crontab 设置服务器定期执行备份工作
    linux创建日期文件名
    代码层读写分离实现
  • 原文地址:https://www.cnblogs.com/767355675hutaishi/p/4299548.html
Copyright © 2011-2022 走看看