1. 程式人生 > >upc 6621: HSI(數學期望,數學推導能力)

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.

來源/分類

[提交] [狀態]

【總結】

我已經第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;
}