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)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. Codeforces Round #381 (Div. 2) C. Alyona and mex(无语)

    题目链接 http://codeforces.com/contest/740/problem/C 题意:有一串数字,给你m个区间求每一个区间内不含有的最小的数,输出全部中最小的那个尽量使得这个最小值最 ...

随机推荐

  1. jekins 持续集成手记

    1.安装一个干净Ubuntu14.04桌面版本 2.打开http://jenkins-ci.org/ 官网, 选择use jenkins 中, Installing Jenkins on Ubuntu ...

  2. android 查看MD5、sha1值命令

    cmd 进去keystore 文件所在目录 keytool -list -v -keystore xxx.keystore debug.keystore 默认目录:C:\Documents and S ...

  3. PHP使用字符串名称调用类的方法

    <?php class Game { function Play($id) { echo "Playing game $id\n"; } } $game = new Game ...

  4. php读取json时无数据(为空)的解决方法

    在使用PHP调用一些json接口文件时 如果使用 file_get_contents 获取页面json数据后 再使用json_decode()解析后 数据无法正常输出 这是的返回值为null 这是由于 ...

  5. java jar包收集

    activation~与javaMail有关的jar包,使用javaMail时应与mail.jar (mail.jar和activation.jar)一起加入到lib中去,具体负责mail的数据源和类 ...

  6. Android之AnimationDrawable初识

    Drawable animation可以加载Drawable资源实现帧动画.AnimationDrawable是实现Drawable animations的基本类. 这里用AnimationDrawa ...

  7. android studio对于错误拼写/不识别的英文单词,给予波浪提示

    使用自己的名字当Tag.却发现有个非常不用好的提示.波浪,我浪个你妹. Typo:In word ‘miyuehu’ less...(Ctrl+F1) spellchecker inspection ...

  8. 关于word excel 等的信息隐藏技术

    简单的word 信息隐藏技术分为两种 一  利用word自带的功能对信息进行隐藏,即选中要隐藏的文字 单击右键 选择字体  给隐藏选项打勾即可    这种信息隐藏比较简单  找到的方式为单机文件——找 ...

  9. Android深度探索HAL与驱动开发 第二章 搭建Android开发环境

    通常以应用移植和系统移植的为Andorid系统移植的主要部分.同时为了适应不同平台硬件设备,对源代码进行相应的修改.除了要移植相适应的CPU架构,最重要是移植Linux驱动. 但是由于一些特别的原因, ...

  10. android Sqlite select * from myDatabase没有内容的问题

    没什么好说的,但是却在初学的时候弄了很久,百度google查了很多资料.后来才发现,竟然是少了个分号结束符的原因. 开始怀疑人生了...