zoukankan      html  css  js  c++  java
  • Alyona and copybooks

    Alyona and copybooks
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard 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 arubles, 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 nabc (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.

    分析:需要仔细考虑所有情况;

       n=4k,ans=0;

       n=4k+1,ans=min({a,b+c,c*3});

         n=4k+2,ans=min({a*2,b,c*2});

       n=4k+3,ans=min({a*3,b+a,c});

    代码:

    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <algorithm>
    #include <climits>
    #include <cstring>
    #include <string>
    #include <set>
    #include <map>
    #include <unordered_map>
    #include <queue>
    #include <stack>
    #include <vector>
    #include <list>
    #define rep(i,m,n) for(i=m;i<=n;i++)
    #define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
    #define mod 1000000007
    #define inf 0x3f3f3f3f
    #define vi vector<int>
    #define pb push_back
    #define mp make_pair
    #define fi first
    #define se second
    #define ll long long
    #define pi acos(-1.0)
    #define pii pair<int,int>
    #define Lson L, mid, ls[rt]
    #define Rson mid+1, R, rs[rt]
    #define sys system("pause")
    #define intxt freopen("in.txt","r",stdin)
    const int maxn=1e5+10;
    using namespace std;
    int gcd(int p,int q){return q==0?p:gcd(q,p%q);}
    ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
    inline ll read()
    {
        ll x=0;int f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    int m,k,t;
    ll n,a,b,c;
    int main()
    {
        int i,j;
        scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
        if(n%4==0)puts("0");
        else
        {
            int p=4-n%4;
            if(p==1)printf("%lld
    ",min({a,b+c,c*3}));
            else if(p==2)printf("%lld
    ",min({a*2,b,c*2}));
            else printf("%lld
    ",min({a*3,b+a,c}));
        }
        //system("Pause");
        return 0;
    }
  • 相关阅读:
    PHP根据蜘蛛和设备进行适配不同界面
    destoon7.0招商地区聚合推送
    Destoon7.0产品栏目地区聚合推送插件
    Destoon7.0百度批量循环推送至百度
    PHP 实现随机图像功能
    PHP中$_SERVER参数用法总结
    关于destoon后台添加自定义功能+前台展示标签调用方法
    分类地区批量推送熊掌号+主动推送代码
    SpringMVC-SimpleDEMO
    SpringMVC工作流程
  • 原文地址:https://www.cnblogs.com/dyzll/p/6102902.html
Copyright © 2011-2022 走看看