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. phonegap android 开发环境搭建

    1.下载JDK并安装   http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html 配置环境变量   ...

  2. PHP 爬虫

    1.爬虫的本质简单来说,就是读取页面源代码,然后用正则匹配得到想要的数据. 示例如下: private function spider_jiuyou_list($listname,$url)    { ...

  3. winform在设置控件enabled=false后,无法更改控件字体颜色的问题

    项目界面设计的时候,发现在设置button的enabled=false后,原本设计的字体颜色跟预设的不一样,查了一些资料后,在网上看到这样一段代码: [System.Runtime.InteropSe ...

  4. Django1.3 创建项目

    经历了各种失败各种烦恼以后Django开发环境终于搭建好了! 系统环境:ubuntu12.04    Django版本1.3.1   Python版本 2.7.3 接下来就兴建一个项目练习一下 1.创 ...

  5. c#中方法的重载

    转自:http://www.cnblogs.com/lovesong_blog/articles/1416617.html string和program都是Object的派生类,string类型是se ...

  6. 第三个Sprint冲刺事后诸葛亮报告

    用户反馈:还好吧. 用户数量:4 团队改进建议:思维局限太大,技术需要革新. 1.每个成员第一个sprint阶段有何需要改进? 成员 需要改进 邵家文 需要提高自己的工作效率,与创新能力,解决问题的能 ...

  7. hibernate中获得session的方式

    his.getsession实际上是调用了父类中的方法获得session.使用spring管理hibernate的SessionFactory的时候,这个方法会从session池中拿出一session ...

  8. Unattend.xml应答文件制作(WISM)

    将制作好的应答文件unattend.xml拷贝到模板机sysprep目录下,然后在cmd下运行 (unattend.xml文件可自定义名称)   sysprep /generalize /oobe / ...

  9. 批量创建SO

    生成一般销售订单和退货订单所要使用的BAPI不同, 一般销售订单: BAPI_SALESORDER_CREATEFROMDAT2 退货订单: BAPI_CUSTOMERRETURN_CREATE 二者 ...

  10. same story,different day

    多亏了这个重感冒,宏伟计划险些又断了. 我是说当然断了一天,但是比起鄙人过往的八千多个日子,喔,虚惊一场. 又看了段lietome,作为不会看眼色的人,这样的美剧太有吸引力了.想象一下,一个八分半美女 ...