Codeforces Round #381 (Div. 2) A.Alyona and copybooks
来源:互联网 发布:ospf算法 编辑:程序博客网 时间:2024/06/06 08:46
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.
题意:
Alyona有n本练习册,现在要买一定数量的练习册使其数量是四的倍数
已知一本价格为a,两本价格为b,三本价格为c,求最少花的钱数
思路:
先将总数模4
若余数为1,需三本,有三种可能性:3×a,a+b,c
若余数为2,需两本,有三种可能性:a×2,b,c×2
若余数为3,需一本,有三种可能性:a,b+c,3×c
注意余数为3, 3×c的情况,一开始没想到,别hack了==
代码:
/************************************************************************* > File Name: 381A.cpp > Author: SIU > Created Time: 2016年11月24日 星期四 00时34分22秒 ************************************************************************/#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>using namespace std;int main(){ int n; long long int a,b,c; scanf("%d",&n); scanf("%lld%lld%lld",&a,&b,&c); if(n%4==0&&n!=0) { printf("0\n"); return 0; } int sum=n%4; if(sum==3) { long long int item; item=min(b+c,min(a,3*c)); printf("%lld\n",item); } else if(sum==2) { long long int item=min(2*a,min(b,2*c)); printf("%lld\n",item); } else if(sum==1) { long long int item; item=min(a*3,min(a+b,c)); printf("%lld\n",item); } return 0;}
- Codeforces Round #381 (Div. 2) A Alyona and copybooks
- Codeforces Round #381 (Div. 2) A.Alyona and copybooks
- Codeforces Round #381 (Div. 2) A. Alyona and copybooks
- Codeforces Round #381 (Div. 2) A. Alyona and copybooks
- Codeforces#381(Div. 2) A.Alyona and copybooks【暴力】
- Codeforces Round #381 (Div. 2) A. Alyona and copybooks(思维)
- Codeforces Round #381 (Div. 2) A. Alyona and copybooks(模拟)
- codeforces 381A. Alyona and copybooks=
- Codeforces Round #381 (Div. 2)D. Alyona and a tree
- Codeforces Round #381 (Div. 2) A. Alyona and flowers
- Codeforces Round #381 (Div. 2) D. Alyona and a tree
- Codeforces Round #381 (Div. 2) D. Alyona and a tree
- 【20.23%】【codeforces 740A】Alyona and copybooks
- Codeforces 740A Alyona and copybooks
- CodeForces 740A Alyona and copybooks
- CodeForces 740A - Alyona and copybooks(思维)
- 740A Alyona and copybooks codeforces
- codeforces 740A Alyona and copybooks
- Window常见问题
- 据前序遍历和中序遍历重建二叉树
- C/C++内存泄漏及检测
- Android数据存储和访问-书籍的增删改查
- php无符号16进制小端模式运算
- Codeforces Round #381 (Div. 2) A.Alyona and copybooks
- win7共享配置
- 真正解决App启动时白屏/黑屏
- Oracle函数
- Exmobi杂谈
- 【转】Virtualbox中5种网络类型
- singularity deploy
- Vue学习(一)概念及常见命令介绍
- Spark 安装配置简单测试