牛客网暑期ACM多校训练营(第四场) J 贪心

链接:

https://www.nowcoder.com/acm/contest/143/J

#include<bits/stdc++.h>
using namespace std;
long long n, p2, p3;
int main(){
    cin >> n >> p2 >> p3;
    double c2 = p2 / 2.0, c3 = p3 / 3.0;

    if(n == 1) cout << (long long)(p2 < p3 ? p2 : p3) << "
";

    else if(c2 <= c3){
        if(n % 2 == 0){
            cout << n / 2 * p2 << "
";
        }else{
            long long temp = p3 - p2;
            temp = temp < p2 ? temp : p2;
            cout << n / 2 * p2 + temp << "
";
        }
    }else {
        if(n%3 == 0){
            cout << n / 3 * p3 << "
";
        }else if(n % 3 == 1){
            long long temp = p2;
            temp = temp < p3 ? temp : p3;
            temp = temp < 2 * p2 - p3 ? temp : 2 * p2 - p3;
            
            cout << n/3 * p3 + temp << "
";
        }else if(n % 3 == 2){
            long long temp = p2;
            
            temp = temp < p3 ? temp : p3;
            
            cout << n/3 * p3 + temp << "
";
        }
    }
    return 0;
}
原文地址:https://www.cnblogs.com/Jadon97/p/9409884.html