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. S2SH三大框架整合(配置及思想)

    花了一下午,终于将struts2.18+hibernate3.5.6+spring2.5.5进行整合,完成功能:在Oracle数据库的TCourse表中插入一条数据. Ⅰ,整合流程:web启动———— ...

  2. dom2和dom3

    第十二章 DOM2和DOM3 一.DOM变化 1.针对XML命名空间的变化 2.其他方面的变化 二.样式 1.访问元素的样式             .style             1)DOM样 ...

  3. map 容器的使用

    C++中map容器提供一个键值对容器,map与multimap差别仅仅在于multiple允许一个键对应多个值. 一.map的说明    1   头文件   #include   <map> ...

  4. 事件冒泡和事件捕获以及解释target和currenttarget的区别

    冒泡和捕获的区别是冒泡事件是先触发子元素事件,再触发父元素事件,这个是冒泡.捕获是先触发父元素事件,再触发子元素事件.简单的来说,冒泡的顺序是由内到外,捕获的顺序是由外到内 举例:<!DOCTY ...

  5. MTP in Android详解

    MTP in Android详解 最近好长一段时间没有做笔记了,今天主要学习一下MTP相关的知识. MTP的全称是Media Transfer Protocol(媒体传输协议),它是微软公司提出的一套 ...

  6. C#基础——winform应用上传图片到SQLServer数据库

    前言 之前通过winform与SQL Server的交互一直局限于文本.数字等信息,都可以通过string的方式来传输,但是比如音乐.图片等特殊格式的文件要如何与SQL Server数据库进行交互呢? ...

  7. 【转】家庭wifi覆盖指导

    网址:家庭wifi覆盖指导 私以为,目前民用 wifi 路由器市场已经完全走上了邪路.天线越来越大,发射功率越做越高.都敢冒着法律的风险使用大大超过 100mW 的发射功率了.且不论巨大的发射功率可能 ...

  8. LintCode Find Minimum In Rotated Sorted Array

    1. 画图, 直观. 2. 讨论数组为空或者个数为零. 3. 讨论首尾, 若为翻转过的则进行查找直到最后两个数进行比较, 取小者. public class Solution { /** * @par ...

  9. linux笔记_防止ddos攻击

    一.什么是DoS攻击 DoS是Denial of Service的简称,即拒绝服务,造成DoS的攻击行为被称为DoS攻击,其目的是使计算机或网络无法提供正常的服务.最常见的DoS攻击有计算机网络带宽攻 ...

  10. 什么是OAuth授权?

    什么是OAuth授权?   一.什么是OAuth协议 OAuth(开放授权)是一个开放标准. 允许第三方网站在用户授权的前提下访问在用户在服务商那里存储的各种信息. 而这种授权无需将用户提供用户名和密 ...