HSI__数学期望

,莫过一日曝十日寒。

6621: HSI

时间限制: 1 Sec  内存限制: 128 MB
提交: 588  解决: 134
[提交] [状态] [讨论版] [命题人:admin]

题目描述

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.

第一份
#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;
}
第二份
#include<cstdio>
using namespace std;
typedef long long ll;
int main()
{
   int n,m;
   scanf("%d%d",&n,&m);
   printf("%lld\n",(ll)((n-m)*100+m*1900)*(1<<m));
   return 0;
}

猜你喜欢

转载自blog.csdn.net/wearegamer/article/details/81662656