Codeforces Round #381 (Div. 2)A. Alyona and copybooks(dfs)
A. Alyona and copybooks
Problem Description:
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.
Sample Input:
1 1 3 4
Sample Output:
3
【题目链接】A. Alyona and copybooks
【题目类型】dfs或暴力
&题意:
你有n本书,你要再买k本,使得n+k能被4整除,a是1本的价钱,b是2本的价钱,c是3本的价钱。问最小价钱是多少?
&题解:
这题刚做的时候想简单了,毕竟只是cf第一题嘛,但最后,发现还是有多种情况的,比如还差1本的时候,也有可能是5本。
这题暴力感觉好麻烦,我就仔细的想了一下,发现可以dfs,num代表本数,res代表多少钱,一定要超过3*n再停止,这样是为了搜索更多可能的情况。
&代码:
#include <bits/stdc++.h>
typedef long long ll;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
ll n, a, b, c, ans;
void dfs(ll num, ll res) {
if (num % 4 == 0) ans = std::min(ans, res);
if (num > 3 * n) return;
dfs(num + 1, res + a);
dfs(num + 2, res + b);
dfs(num + 3, res + c);
}
int main() {
while (~scanf("%d%d%d%d",&n,&a,&b,&c)) {
ans = LINF;
n %= 4;
dfs(n, 0);
printf("%d\n",ans);
}
return 0;
}
Codeforces Round #381 (Div. 2)A. Alyona and copybooks(dfs)的更多相关文章
- Codeforces Round #381 (Div. 1) B. Alyona and a tree dfs序 二分 前缀和
B. Alyona and a tree 题目连接: http://codeforces.com/contest/739/problem/B Description Alyona has a tree ...
- Codeforces Round #381 (Div. 1) A. Alyona and mex 构造
A. Alyona and mex 题目连接: http://codeforces.com/contest/739/problem/A Description Alyona's mother want ...
- Codeforces Round #381 (Div. 2) D. Alyona and a tree 树上二分+前缀和思想
题目链接: http://codeforces.com/contest/740/problem/D D. Alyona and a tree time limit per test2 secondsm ...
- Codeforces Round #381 (Div. 2)D. Alyona and a tree(树+二分+dfs)
D. Alyona and a tree Problem Description: Alyona has a tree with n vertices. The root of the tree is ...
- Codeforces Round #381 (Div. 2)C. Alyona and mex(思维)
C. Alyona and mex Problem Description: Alyona's mother wants to present an array of n non-negative i ...
- Codeforces Round #381 (Div. 2)B. Alyona and flowers(水题)
B. Alyona and flowers Problem Description: Let's define a subarray as a segment of consecutive flowe ...
- Codeforces Round #381 (Div. 2)C Alyona and mex
Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be ...
- Codeforces Round #381 (Div. 2) D. Alyona and a tree dfs序+树状数组
D. Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Codeforces Round #381 (Div. 2) C. Alyona and mex(无语)
题目链接 http://codeforces.com/contest/740/problem/C 题意:有一串数字,给你m个区间求每一个区间内不含有的最小的数,输出全部中最小的那个尽量使得这个最小值最 ...
随机推荐
- Java 正则表达式 量词 --- 三种匹配模式【贪婪型、勉强型、占有型】
1.Greediness(贪婪型):最大匹配X?.X*.X+.X{n,}都是最大匹配.例如你要用“<.+>”去匹配“a<tr>aava</tr>abb”,也许你所期 ...
- ASP.NET 学习记录之一
(放着期末考试不复习,我每天废寝忘食地阅读从图书馆借来的ASP.NET相关专业书籍,到现在快一个星期,终于掌握了点东西,但是一拿到真刀真枪就做不出来什么了:老师把实验室打开,我就在这码码代码咯) As ...
- NOPI导出加载模板
ListExcel导出(加载模板) /// <summary> /// List根据模板导出ExcelMemoryStream /// </summary> /// <p ...
- mongo链接solr的过程与问题
我的环境: 1:ubunt 16 2:mongodb 2.6.1 3:solr 6.3 4:JDK 1.8 准备过程: 1:安装mongo-connector #pip install mongo-c ...
- 手动刷新magento的索引管理方法
当我们网站商品很多的时候,比如有几千件,我们刷新Magento的索引管理(Index Management)经常会失败.那么后台刷新不了,我们还可以通过命令行来刷新. 使用命令行来刷新索引管理会极大降 ...
- 通过样式class 判断多个checkbox redio 是否都选中
var count = "${count}"; for(var i=1;i<=count;i++){ var flag = false; if($("input[c ...
- DNS的查询流程
我们可以通过一个命令了演示,同时进行抓包. 在OS X可以用dig命令进行查询追踪. dig @8.8.8.8 www.baidu.com 看看输出会是什么呢 ; <<>> D ...
- UDP收发buffer尺寸对收发包流量的影响
下午验证一个高流量发包问题时,发现了一个值得记录的问题:socket的收发buffer尺寸是会影响收发包的效率的,高流量通讯时,若socket的收发buffer尺寸过小会一定程度降低收发包效率. 自己 ...
- oracle 锁表查询与解锁
查询锁住的表 SELECT s.sid, s.serial#, s.username, s.schemaname, s.osuser, s.process, s.machine,s.terminal, ...
- 用bugzilla统计BUG
bugzilla—— reports—— Tabular reports—— 选择版本号啥的跟search一样 上面的行标Vertical Axis选Resolution:列标Horizontal A ...