zoukankan      html  css  js  c++  java
  • Codeforces 740A Alyona and copybooks

    题意:某人现有n本书,想再拥有k本书,使得(n % k) == 0,求买k本书最少花多少钱。已知a元买1本书,b元买2本书,c元买3本书。

    分析:n对4取余,可分为4种情况:(t = n % 4)(每个情况下考虑a,b,c的所有组合)

    1、t == 0,则不必花钱买书。

    2、t == 3,还需买1本,

    (1)完全用a元买---------用a元买1本

    (2)完全用c元买---------用3c元买9本(因为a可能很大,然后c很小)

    (3)可以用b + c买-------用b + c元共买5本

    (4)肯定不能完全用b元买,(因为b元买2本,无论怎么买,总数都不会被4整除)

    (5)此外肯定不能用a + b, a + c,a + b + c买,因为a元买1本即可达到目的,用a + b,a + c,a + b + c花的钱显然比a多,而且没必要买那么多

    3、t == 2,还需买2本,

    (1)完全用a买-----------用2a元买2本

    (2)完全用b买-----------用b元买2本

    (3)完全用c买-----------用2c元买6本

    (4)同理,没必要用a + b,b + c, a + b + c买,因为b元买2本即可达到目的。也没必要用a + c买,因为a + c买的是4本,不管怎么买,总数都不会被4整除

    4、t == 1,还需买3本,

    (1)完全用a买-----------用3a元买3本

    (2)完全用c买-----------用c元买3本

    (3)用a + b买-----------用a + b买共买3本

    (3)肯定不能完全用b元买,因为无论怎么买,总数都不会被4整除

    (4)同理,没必要用a + c,b + c, a + b + c买,因为c元买3本即可达到目的。

    #pragma comment(linker, "/STACK:102400000, 102400000")
    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<cctype>
    #include<cmath>
    #include<iostream>
    #include<sstream>
    #include<iterator>
    #include<algorithm>
    #include<string>
    #include<vector>
    #include<set>
    #include<map>
    #include<stack>
    #include<deque>
    #include<queue>
    #include<list>
    #define Min(a, b) ((a < b) ? a : b)
    #define Max(a, b) ((a < b) ? b : a)
    typedef long long ll;
    typedef unsigned long long llu;
    const int INT_INF = 0x3f3f3f3f;
    const int INT_M_INF = 0x7f7f7f7f;
    const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
    const ll LL_M_INF = 0x7f7f7f7f7f7f7f7f;
    const int dr[] = {0, 0, -1, 1};
    const int dc[] = {-1, 1, 0, 0};
    const int MOD = 1e9 + 7;
    const double pi = acos(-1.0);
    const double eps = 1e-8;
    const int MAXN = 100000 + 10;
    const int MAXT = 10000 + 10;
    using namespace std;
    int main(){
        ll n, a, b, c;
        while(scanf("%lld%lld%lld%lld", &n, &a, &b, &c) == 4){
            if(n % 4 == 0){
                printf("0\n");
                continue;
            }
            ll tmp = ll(4) - ll(n % 4);
            if(tmp == ll(1)){
                ll t = Min(a, 3 * c);
                t = Min(t, b + c);
                printf("%lld\n", t);
                continue;
            }
            if(tmp == ll(2)){
                ll t = Min(2 * a, b);
                t = Min(2 * c, t);
                printf("%lld\n", t);
                continue;
            }
            if(tmp == (3)){
                ll t = Min(3 * a, c);
                t = Min(t, a + b);
                printf("%lld\n", t);
                continue;
            }
        }
        return 0;
    }
  • 相关阅读:
    leetcode面试准备:Kth Largest Element in an Array
    leetcode面试准备:Minimum Size Subarray Sum
    leetcode面试准备:Valid Anagram
    leetcode面试准备:Divide Two Integers
    leetcode面试准备:Container With Most Water
    面试:归并排序和分治法
    leetcode面试准备:Lowest Common Ancestor of a Binary Search Tree & Binary Tree
    Leetcode解题思想总结篇:双指针
    leetcode面试准备: CountPrimes
    RF中BDD编写
  • 原文地址:https://www.cnblogs.com/tyty-Somnuspoppy/p/6124198.html
Copyright © 2011-2022 走看看