upc 6621: HSI(数学期望,数学推导能力)

6621: HSI

时间限制: 1 Sec  内存限制: 128 MB
提交: 544  解决: 112
[提交] [状态] [讨论版] [命题人: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.

来源/分类

ABC078&ARC085 

[提交] [状态]

【总结】

我已经第n次读不懂atcoder的题是啥意思了,他就不能说明白一点,细节强调一下。md

【题意】

Takahashi是打acm的,他提交了一个题,后台有n组测试数据,他提交后,有m组超时了。

那么这个意思呢就是 我只要进行一次提交,不管过没过,这个题目中总是有m组测试数据耗时1900ms,n-m组耗时100ms。

每次提交,对于每一组超时的数据,有1/2的概率能通过。

问:当他过了这个题的时候,总的耗时的数学期望是多少。总的耗时是指:每次提交每组数据用的时间,而且每进行一次提交,耗费的时间是固定的=1900m+100(n-m)

【分析】

令x=1900m+100(n-m),即每次提交需要花费的时间

令p=1/(2^m),意思是 某次提交,m组超时的数据全部通过的概率

期望公式\sum k*p(k),k是提交次数,下面我们求出提交次数的数学期望来,再乘上每次的耗时,就是耗时期望了。

第一次提交的贡献:1*p

第二次提交的贡献:2*(1-p)*p   ( (1-p)*p表示第一次提交没通过,并且第二次通过的概率)

第三次提交的贡献:3*(1-p)^2*p  ( (1-p)^2*p 表示前两次提交都没通过,并且第三次通过的概率)

第四次.....一直到第正无穷项。。。

将上面的式子加起来得:

ans=1p + 2(1-p)^{1}p+3(1-p)^{2}p+...+k(1-p)^{k-1}p

=p(1 + 2(1-p)^{1}+3(1-p)^{2}+...+k(1-p)^{k-1})

 

令            res=1 + 2(1-p)^{1}+3(1-p)^{2}+...+k(1-p)^{k-1}             ①式

(1-p)res=1(1-p)^{1} + 2(1-p)^{2}+3(1-p)^{3}+...+k(1-p)^{k}   ②式

①-②得:

p*res=1+(1-p)^{1}+(1-p)^{2}+....+(1-p)^{k-1}-k(1-p)^{k}

根据等比数列前n项和公式可得:

p*res=\frac{1-(1-p)^{k}}{p} -k(1-p)^{k}

化简可得:

res= \frac{1}{p^{2}}-\frac{(1-p)^k(1+p^{2}k)}{p^{2}}

由于k趋向于正无穷,其中被减数有一项k作为指数,那被减数的指定服从这个值。因为1-p<1,所以被减数趋近于0

res= \frac{1}{p^{2}}-0

所以ans=p*res= \frac{1}{p}

这就是提交次数的期望,再乘上1900m+100(n-m)即为答案;

【代码】

/****
***author: winter2121
****/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int n,m;
    cin>>n>>m;
    //神仙题的化简
    cout<<(1900*m+100*(n-m))*(1<<m)<<endl;
}

 

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

雪的期许

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值