HSI(数学期望)

题目描述

Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is YES or NO.
When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases.
Then, he rewrote the code to correctly solve each of those M cases with 1⁄2 probability in 1900 milliseconds, and correctly solve each of the other N−M cases without fail in 100 milliseconds.
Now, he goes through the following process:
Submit the code.
Wait until the code finishes execution on all the cases.
If the code fails to correctly solve some of the M cases, submit it again.
Repeat until the code correctly solve all the cases in one submission.
Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).

Constraints
All input values are integers.
1≤N≤100
1≤M≤min(N,5)

 

输入

Input is given from Standard Input in the following format:
N M

 

输出

Print X, the expected value of the total execution time of the code, as an integer. It can be proved that, under the constraints in this problem, X is an integer not exceeding 109.

 

样例输入

1 1

 

样例输出

3800

 

提示

In this input, there is only one case. Takahashi will repeatedly submit the code that correctly solves this case with 1⁄2 probability in 1900 milliseconds.
The code will succeed in one attempt with 1⁄2 probability, in two attempts with 1⁄4 probability, and in three attempts with 1⁄8 probability, and so on.
Thus, the answer is 1900×1⁄2+(2×1900)×1⁄4+(3×1900)×1⁄8+…=3800.

题解:数学期望题,一开始真的没弄懂,都快做疯了。我的理解是先算出每道题都做对的期望,然后再进行10000次左右的模拟。

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    double x,y,z=1.0,sum=0,s,ti;
    cin>>n>>m;
    s=pow(0.5,m);//算出所有TLE题目做对的概率
    x=ti=(1900*m)+(n-m)*100;
    sum=ti*s;//第一次提交的时间
    for(int i=1;i<10000;i++)
    {
        z*=(1-s);//做不对的概率
        x+=ti;//时间增加
        sum+=x*s*z;//此时用的时间乘以做不对的概率再乘以做对的概率
    }
    cout<<sum<<endl;
}

下面的是题解给出的AC代码,有看懂的同学能不教教我。。——。。——


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;

int main()
{
    ll n,m;
    cin>>n>>m;
    cout<<(1ll<<m)<<endl;
    cout<<(1ll<<m)*(m*1900+(n-m)*100)<<endl;
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值