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.
The only line contains 4 integers n, a, b, c (1 ≤ n, a, b, c ≤ 109).
Print the minimum amount of rubles she should pay to buy such number of copybooks k that n + k is divisible by 4.
1 1 3 4
3
6 2 1 1
1
4 4 4 4
0
999999999 1000000000 1000000000 1000000000
1000000000
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/contest/740/problem/A
题意:当前有n本书,需要买k本书,使得(n+k)是4的倍数。现在,买一本书需要a元,买2本书需要b元,买3本书需要k元。求最少需要花多少钱。
思路:模拟。因为a,b,c其中有可能会有价格悬殊较大的情况,所以并不是买的越少越好。
n%4 买书的钱
1 3a,b+a,c;
2 2a,b,2c;
3 a,b+c,3c;
这就是所有情况,输出最小的就可以了。
代码:
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<algorithm> 6 using namespace std; 7 typedef __int64 ll; 8 const int MAXN=1e5+100; 9 const __int64 INF=1e9+100; 10 int main() 11 { 12 __int64 n,a,b,c; 13 scanf("%I64d%I64d%I64d%I64d",&n,&a,&b,&c); 14 b=min(2*a,b); 15 c=min(min(3*a,a+b),c); 16 n=n%4; 17 if(n==0) cout<<0<<endl; 18 else if(n==1) 19 cout<<min(min(3*a,a+b),c); 20 else if(n==2) 21 cout<<min(min(2*a,b),2*c); 22 else 23 cout<<min(min(a,b+c),3*c); 24 return 0; 25 }