6621: HSI

Posted lwsh123k

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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组超时的数据全部通过的概率

期望公式技术分享图片,k是提交次数,下面我们求出提交次数的数学期望来,再乘上每次的耗时,就是耗时期望了。

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

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

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

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

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

将上面的式子加起来得:

技术分享图片

技术分享图片

 

令            技术分享图片             ①式

技术分享图片   ②式

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

①-②得:

技术分享图片

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

技术分享图片

化简可得:

技术分享图片

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

技术分享图片

所以技术分享图片

这就是提交次数的期望,再乘上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



















以上是关于6621: HSI的主要内容,如果未能解决你的问题,请参考以下文章

2019杭电多校第四场hdu6621 K-th Closest Distance(二分答案+主席树)

hdu6621--主席树

HDU6621 K-th Closest Distance HDU2019多校训练第四场 1008(主席树+二分)

[hdu-6621]K-th Closest Distance 主席树 线段树 2019 多校4

2019杭电多校赛第四场 HDU6621 K-th Closest Distance 主席树 二分

HDU - 6621 K-th Closest Distance 主席树+二分答案