A. Alyona and copybooks
time limit per test:

1 second

memory limit per test:

256 megabytes

input:

standard input

output:

standard output

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 arubles, 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 nabc (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.

Examples
input
1 1 3 4
output
3
input
6 2 1 1
output
1
input
4 4 4 4
output
0
input
999999999 1000000000 1000000000 1000000000
output
1000000000
Note

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.

题目链接:http://codeforces.com/contest/740/problem/A


题意:当前有n本书,需要买k本书,使得(n+k)是4的倍数。现在,买一本书需要a元,买2本书需要b元,买3本书需要k元。求最少需要花多少钱。

思路:模拟。因为a,b,c其中有可能会有价格悬殊较大的情况,所以并不是买的越少越好。

n%4  买书的钱

1    3a,b+a,c;

2    2a,b,2c;

3    a,b+c,3c;

这就是所有情况,输出最小的就可以了。

代码:

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef __int64 ll;
const int MAXN=1e5+;
const __int64 INF=1e9+;
int main()
{
__int64 n,a,b,c;
scanf("%I64d%I64d%I64d%I64d",&n,&a,&b,&c);
b=min(*a,b);
c=min(min(*a,a+b),c);
n=n%;
if(n==) cout<<<<endl;
else if(n==)
cout<<min(min(*a,a+b),c);
else if(n==)
cout<<min(min(*a,b),*c);
else
cout<<min(min(a,b+c),*c);
return ;
}

Codeforces 740A. Alyona and copybooks 模拟的更多相关文章

  1. CodeForces 740A Alyona and copybooks

    完全背包. 直接做个背包容量为$100000$的完全背包,这样就可以避免繁琐的分类讨论了. #pragma comment(linker, "/STACK:1024000000,102400 ...

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

  3. CodeForces.158A Next Round (水模拟)

    CodeForces.158A Next Round (水模拟) 题意分析 校赛水题的英文版,坑点就是要求为正数. 代码总览 #include <iostream> #include &l ...

  4. Codeforces E. Alyona and a tree(二分树上差分)

    题目描述: Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  5. 【20.23%】【codeforces 740A】Alyona and copybooks

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. Codeforces 740C. Alyona and mex 思路模拟

    C. Alyona and mex time limit per test: 2 seconds memory limit per test: 256 megabytes input: standar ...

  7. Codeforces 747C:Servers(模拟)

    http://codeforces.com/problemset/problem/747/C 题意:有n台机器,q个操作.每次操作从ti时间开始,需要ki台机器,花费di的时间.每次选择机器从小到大开 ...

  8. CodeForces 682A Alyona and Numbers (水题)

    Alyona and Numbers 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/A Description After fi ...

  9. Codeforces 716A Crazy Computer 【模拟】 (Codeforces Round #372 (Div. 2))

    A. Crazy Computer time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

随机推荐

  1. Winform 窗体控件随窗体自动(等比例)调整大小

    新建窗体程序了,添加窗体事件Load(加载窗体时).Resize(调整控件大小时).自定义方法setTag(获取控件的width.height.left.top.字体大小等信息的值).setContr ...

  2. IOS学习之路--OC的基础知识

    1.项目经验 2.基础问题 3.指南认识 4.解决思路 ios开发三大块: 1.Oc基础 2.CocoaTouch框架 3.Xcode使用 -------------------- CocoaTouc ...

  3. Office 365 系列一 ------- 如何单个安装Office 客户端和Skype for business

    当我们注册好或者购买好 Office 365后,我们的单个用户如何进行在线的.流式的方式安装好我们的客户端,特别是对于我们非IT部门来说,这是一个比较为难的事情, 经常需要我们的IT去到同事的电脑旁边 ...

  4. 介绍一款非常适合做微网站并且免费的CMS系统

    在微网站火热的今天,寻找一款具备 web app功能的CMS系统能够大大提高我们的工作效率,eBSite升级到3.0后,开始支持web app 皮肤,也就是创建一个站点,会同时绑定一个PC版皮肤与一个 ...

  5. NSDate管理日期和时间

    //时间初始化        NSDate *date = [[NSDate alloc]initWithString:@"2010-01-01 23:59:59 +0900"]; ...

  6. 学习shell脚本笔记

    1.if 是单分支语句,使用格式如下: if condition ; then statement ….. fi 2.if … else 是双分支语句,使用格式如下: if condition ; t ...

  7. R常见的几种常见统计图

    1,向日葵散点图 2,热图  (颜色越深,数值越大) 3,折线图(散点图),绘制散点图集用 paris(data.frame)

  8. npm -v 一直闪

    一直闪一般是配置搞错了 参考: windows安装完nodejs后做了相关环境变量配置后,cmd输入npm没反应啊 就光标一直闪 node是正常的 或者 https://segmentfault.co ...

  9. jQuery插件制作方法

    html页面:<h1>Hello My name is Alex,i from china.</h1> 1.无参数实现文字阴影效果 测试代码: $("h1" ...

  10. maven 编译项目时:报com.sun.image.codec.jpeg不存在

    项目中用到图片处理相关的一些工具类,在eclipse开发工具内,程序并没有什么问题,都可以正常使用,项目也没有报错,但通过maven 进行编译打包时,则会报错: 程序包com.sun.image.co ...