• 【20.23%】【codeforces 740A】Alyona and copybooks


    time limit per test1 second
    memory limit per test256 megabytes
    inputstandard input
    outputstandard output
    Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook’s packs in the shop: it is possible to buy one copybook for a rubles, a pack of two copybooks for b rubles, and a pack of three copybooks for c rubles. Alyona already has n copybooks.

    What is the minimum amount of rubles she should pay to buy such number of copybooks k that n + k is divisible by 4? There are infinitely many packs of any type in the shop. Alyona can buy packs of different type in the same purchase.

    Input
    The only line contains 4 integers n, a, b, c (1 ≤ n, a, b, c ≤ 109).

    Output
    Print the minimum amount of rubles she should pay to buy such number of copybooks k that n + k is divisible by 4.

    Examples
    input
    1 1 3 4
    output
    3
    input
    6 2 1 1
    output
    1
    input
    4 4 4 4
    output
    0
    input
    999999999 1000000000 1000000000 1000000000
    output
    1000000000
    Note
    In the first example Alyona can buy 3 packs of 1 copybook for 3a = 3 rubles in total. After that she will have 4 copybooks which she can split between the subjects equally.

    In the second example Alyuna can buy a pack of 2 copybooks for b = 1 ruble. She will have 8 copybooks in total.

    In the third example Alyona can split the copybooks she already has between the 4 subject equally, so she doesn’t need to buy anything.

    In the fourth example Alyona should buy one pack of one copybook.

    【题目链接】:http://codeforces.com/problemset/problem/740/A

    【题解】

    题意:让你加上若干个1,2,3;然后使得n变成n+k;要求n+k能被4整除,并且数字1、2、3都有相应的价格,问价格最小是多少;
    做法:
    我是先用二分搞出比n大的第一个能被4整除的数字是多少->ans*4;
    然后用ans*4-n;得到now;
    然后根据now的大小分情况讨论;
    now==0,不用数字输出0;
    now==1,1个a、或b+c=5,或3个c->9;
    now==2,1个b,两个a或2个c都行
    now==3,3个a,||1个c,||a+b;
    因为a,b,c大小可能很悬殊,所以几种情况都要比较;

    【完整代码】

    #include <bits/stdc++.h>
    #define LL long long
    using namespace std;
    
    const int MAXN = 1e9;
    
    LL n,a,b,c;
    
    int main()
    {
        //freopen("F:\rush.txt","r",stdin);
        cin >> n >> a >> b >> c;
        LL now = 0;
        LL l = 0,r = MAXN,ans = 0;
        while (l <= r)
        {
            LL m = (l+r)>>1;
            if (4*m>=n)
            {
                ans = m;
                r = m-1;
            }
            else
                l = m+1;
        }
        if (4*ans == n)
            puts("0");
        else
        {
            LL now = ans*4-n;
            LL temp = 0;
            if (now==1)
            {
                temp = a;
                temp = min(temp,b+c);
                temp = min(temp,c*3);
            }
            else
                if (now == 2)
                {
                    temp = b;
                    temp = min(temp,a*2);
                    temp = min(temp,2*c);
                }
                else
                    if (now ==3)
                    {
                        temp = c;
                        temp = min(temp,a*3);
                        temp = min(temp,b+a);
                    }
            cout << temp << endl;
        }
        return 0;
    }
  • 相关阅读:
    android传送照片到FTP服务器
    Android对ScrollView滚动监听,实现美团、大众点评的购买悬浮效果
    android上传图片至服务器
    android中如何处理cookie
    【265】shell文件创建链接
    【264】◀▶ Windows 批处理(CMD)
    【263】Linux 添加环境变量 & 全局 shell 脚本
    【262】pscp命令 实现windows与linux互传文件
    合泰 HT66F30 定时器初始化
    错误 是否保存对以下各项的更改 devenv.sin
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626945.html
Copyright © 2020-2023  润新知