6621: 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.

 

解:Repeat until the code correctly solve all the cases in one submission.,一定要注意这句话,他的意思是重复这句话“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.”再重写这m个问题

理解1:

首先感谢dalao写的,转一下。

https://blog.csdn.net/winter2121/article/details/81489377

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

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

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

k的解释:第一次提交耗时x,第二次2x,第n次就是nx

第一次提交的贡献: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}   ②式

其实这个1.2式就是等差数列与等比数列想乘的前n项和,写出Sn,q*Sn,相减即可。

①-②得:

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)即为答案;

理解2:

虽说比较简单,但是不容易想到这个。。。

代码如下:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,m;
    cin>>n>>m;
    cout<<(100*(n-m)+1900*m)*(1<<m)<<endl;
    return 0; 
}

好吧,就这些,再次感谢dalao。

Ooooooo

转载于:https://www.cnblogs.com/lwsh123k/p/9443000.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 内容概要 《计算机试卷1》是一份综合性的计算机基础和应用测试卷,涵盖了计算机硬件、软件、操作系统、网络、多媒体技术等多个领域的知识点。试卷包括单选题和操作应用两大类,单选题部分测试学生对计算机基础知识的掌握,操作应用部分则评估学生对计算机应用软件的实际操作能力。 ### 适用人群 本试卷适用于: - 计算机专业或信息技术相关专业的学生,用于课程学习或考试复习。 - 准备计算机等级考试或职业资格认证的人士,作为实战演练材料。 - 对计算机操作有兴趣的自学者,用于提升个人计算机应用技能。 - 计算机基础教育工作者,作为教学资源或出题参考。 ### 使用场景及目标 1. **学习评估**:作为学校或教育机构对学生计算机基础知识和应用技能的评估工具。 2. **自学测试**:供个人自学者检验自己对计算机知识的掌握程度和操作熟练度。 3. **职业发展**:帮助职场人士通过实际操作练习,提升计算机应用能力,增强工作竞争力。 4. **教学资源**:教师可以用于课堂教学,作为教学内容的补充或学生的课后练习。 5. **竞赛准备**:适合准备计算机相关竞赛的学生,作为强化训练和技能检测的材料。 试卷的目标是通过系统性的题目设计,帮助学生全面复习和巩固计算机基础知识,同时通过实际操作题目,提高学生解决实际问题的能力。通过本试卷的学习与练习,学生将能够更加深入地理解计算机的工作原理,掌握常用软件的使用方法,为未来的学术或职业生涯打下坚实的基础。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值