acm Alyona and copybooks 新人水题

Description

Little girl Alyona is in a shop to buy some copybooks forschool. She study four subjects so she wants to have equal numberof copybooks for each of the subjects. There are three types ofcopybook's packs in the shop: it is possible to buy one copybookfor a rubles, a pack of twocopybooks for b rubles, and apack of three copybooks for crubles. Alyona already has ncopybooks.

What is the minimum amount of rubles she should pay to buy suchnumber of copybooks k thatn + k is divisible by4? There are infinitely many packs ofany type in the shop. Alyona can buy packs of different type in thesame purchase.

Input

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

Output

Print the minimum amount of rubles she should pay to buy suchnumber of copybooks k thatn + k is divisible by4.

Sample Input

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

Hint

In the first example Alyona can buy 3 packs of 1copybook for 3a = 3 rubles intotal. After that she will have 4copybooks 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 alreadyhas between the 4 subject equally, soshe doesn't need to buy anything.

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


以下是我的思路,因为要求最小的数,所以我定义了一个求最小值的函数

先对小女孩已有书求余,看看还需要几本,一共有四种情况

余数为0,,这种情况最简单,不需要再买,所以直接输出0
余数为3,需要本数需要满足,n*4+3,买三个一本,买一本加买两本,或者买直接买三本,三种情况比较大小余数为2,满足n*4+2,买两个一本,买一个两本,或者买两个三本,三种情况比较大小
余数为1,满足n*4+1,买一个一本,买一个三本加一个三本,买三个三本,三种情况比较

以上,新手做题可能方法比较麻烦,求大神指导。

#include
#include

long long int min(long long int x, long long int y)
{
      if(x >= y) return y;
      else return x;
}

int main()
{
    int n, i, x;
    long long int a, b, c;
    long long int min(long long int, long long int);

    while ( scanf("%d", &n) != EOF)
    {
        scanf("%I64d%I64d%I64d", &a, &b, &c);
        x = n%4;
        if(x == 0) printf("%d\n", 0);
        if(x == 3)
        {
              printf("%I64d\n", min(a,min(b+c,c*3)));
        }
        if(x == 2)
        {
              printf("%I64d\n", min(a*2,min(b,c*2)));
        }
        if(x == 1)
        {
              printf("%I64d\n", min(a*3,min(a+b,c)));
        }

    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值