您的位置:首页 > 运维架构

acm Alyona and copybooks 新人水题

2017-01-21 11:07 519 查看
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息