Question summary-Delayed Work

Question summary-Delayed Work


Analysis of the original title
Title description
:

This question is to calculate the minimum payment amount, which consists of two parts: the worker's wages and fines. According to the description of the question, the expression of salary: M X, the expression of fine: (K P)/M, so the total amount expression: M X+(K P)/M, where K, P, X are all Known, the expression becomes a check function of M, and because M>0, according to the nature of the check function, when M=sqrt((K P)/X), the expression obtains the minimum Value, but since M must be an integer, it can be substituted into the verification when M is (int)sqrt((K P)/X) and (int)sqrt((K*P)/X)+1 respectively (according to the function image , Since M must be an integer, compare the two integers closest to the minimum point. Of course, the minimum point may also be an integer, so you can compare it one more time, but it doesn’t matter. How can it be so QAQ), The smaller value is the minimum payment amount required

Many problems require some corresponding mathematical knowledge to be able to solve them easily, so if you want to learn the number algorithm, you must learn mathematics well...

Code

#include<bits/stdc++.h>      //万能头文件
using namespace std;
int main()
{
    
    
    double k,p,x;
    cin>>k>>p>>x;
    //离最小值点最近的两个正整数
    int a=(int)sqrt((k*p)/x);      
    int b=a+1;
    double s1,s2;
    //分别代入计算两个整数点的值,也就是两个点对应的支付金额
    s1=((k*p)/a)+x*a;
    s2=((k*p)/b)+x*b;
    if(s1>s2)
    {
    
    
        printf("%.3lf\n",s2);
    }
    else
    {
    
    
        printf("%.3lf\n",s1);
    }
    //system("pause");
    return 0;
}

Guess you like

Origin blog.csdn.net/m0_46772594/article/details/107871569