题解:AT_arc054_b [ARC054B] ムーアの法則

· · 题解

这里来一篇纯摩尔定律计算的题解。

思路

首先思考摩尔的指数。计算机速度每 1.5 年翻倍,所以我们先设当前速度为 v_0,则 n 年后的速度为 v(n)=v_0\times2^{n/1.5}。

第二想如何计算时间。题面中提出由于现代计算机需要 P 年,则 n 年后的时间为 \frac{P}{2^{n/1.5}}。

第三将 n 年再加上刚刚计算出的时间得到总时间。

到这里开始第二部分的推导。

第一对于推导出来的总时间求导并找到边界点:f(n)=n+P\times2^{-n/1.5}。令导数为 0 后求导,解出 2^{-n/1.5}=\frac{1.5}{P\times \operatorname{log_2}}。提取出 \operatorname{log_2},得到:n=\frac{1.5}{\operatorname{log_2}}\times \operatorname{log}(\frac{P\times \operatorname{log_2}}{1.5})。

最后一步是判断情况。如果 \frac{P\times \operatorname{log_2}}{1.5}\le1,简单分析可知 n\le0,根据题意直接输出 P。否则利用公式计算总时间。

code

#include<bits/stdc++.h>
#define ll long long
#define INF 0x3f3f3f3f  
using namespace std;
int main(){
    double n;
    cin>>n;
    double log2=log(2);
    double temp=(n*log2)/1.5;
    if(temp<=1.0){
        cout<<fixed<<setprecision(10)<<n<<'\n';
    }
    else{
        double t=(1.5/log2)*log(temp);
        cout<<fixed<<setprecision(10)<<t+n/pow(2,t/1.5)<<'\n';
    }
    return 0;
}