codeforces 740A Alyona and copybooks
来源:互联网 发布:李荣浩后羿知乎 编辑:程序博客网 时间:2024/04/30 19:49
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.
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.
一看题确认水题 大致思路就是先把n%4 再看需要多少本 但是依然有一些细节需要考虑
1.数据范围大小 应该是long long
2.比较函数n=4-n%4
n=4,ans=0;
n=1,ans=min(a,b+c,c*3)
n=2,ans=min(a*2,b,c*2)
n=3,ans=min(a*3,a+b,c)
这里的1,2种情况容易漏
#include<iostream>using namespace std;long long min(long long a,long long b){ return a<b?a:b;}long long min(long long a,long long b,long long c){ return min(min(a,b),min(a,c));}int main(){long long n,a,b,c;long long ans;cin>>n>>a>>b>>c;n=4-n%4;if(n==4) ans=0;else if (n==1) ans=min(a,b+c,c*3);else if (n==2) ans=min(a*2,b,c*2);else ans=min(a*3,a+b,c);cout<<ans<<endl;return 0;}
- 【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
- codeforces 381A. Alyona and copybooks=
- A.Alyona and copybooks
- A. Alyona and copybooks
- CF 740 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 Round #381 (Div. 2) A. Alyona and copybooks
- A. Alyona and copybooks--思维水题
- Codeforces Round #381 (Div. 2) A. Alyona and copybooks(思维)
- Codeforces Round #381 (Div. 2) A. Alyona and copybooks(模拟)
- JDK中plugin.jar包目录结构
- POJ No.3617-Best Cow Line(字典序最小问题)
- Java的锁机制
- python 环境搭建(二) pip源的修改
- 【新手】关于进制转换
- codeforces 740A Alyona and copybooks
- Codeforces Round #382 (Div. 2) 735A - Ostap and Grasshopper
- Path Sum II ---LeetCode
- 员工没热情?这8个简单方法比加薪都管用
- spring 之 PropertiesLoaderUtils 获取文件属性用法
- 深度学习的40种应用
- Codeforce 382总结
- Rotate List
- 流氓鲁大师劫持了我的谷歌浏览器