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.
来源/分类
【总结】
我已经第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组超时的数据全部通过的概率
期望公式,k是提交次数,下面我们求出提交次数的数学期望来,再乘上每次的耗时,就是耗时期望了。
第一次提交的贡献:1*p
第二次提交的贡献:2*(1-p)*p ( (1-p)*p表示第一次提交没通过,并且第二次通过的概率)
第三次提交的贡献:3*(1-p)^2*p ( (1-p)^2*p 表示前两次提交都没通过,并且第三次通过的概率)
第四次.....一直到第正无穷项。。。
将上面的式子加起来得:
令 ①式
则 ②式
①-②得:
根据等比数列前n项和公式可得:
化简可得:
由于k趋向于正无穷,其中被减数有一项k作为指数,那被减数的指定服从这个值。因为1-p<1,所以被减数趋近于0
故
所以
这就是提交次数的期望,再乘上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;
}