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. JS面向对象的程序设计

    面向对象的语言有一个标志,即拥有类的概念,抽象实例对象的公共属性与方法,基于类可以创建任意多个实例对象,一般具有封装.继承.多态的特性!但JS中对象与纯面向对象语言中的对象是不同的,ECMA标准定义J ...

  2. 利用IDL将一个txt文档拆分为多个

    测试.txt文档,每47行的格式相同,通过代码每47行存为一个txt,txt文档命名为其第一行数据. 代码如下: file='G:\data\测试.txt' openr,lun,file,/Get_L ...

  3. windows Service 创建部署

    Windows Service简介: 一个Windows服务程序是在Windows操作系统下能完成特定功能的可执行的应用程序.Windows服务程序虽然是可执行的,但是它不像一般的可执行文件通过双击就 ...

  4. php中cookie技术关于跨目录调用cookie值的问题

    今天做项目发现了一个奇葩错误,以cookie技术为主,反复测试发现cookie不能跨目录调用. 我在F:wamp\www\test\下面有1.php和2.php其中1.php接受2.php中setco ...

  5. vi、vim 查找替换

    vi/vim 中可以使用 :s 命令来替换字符串.该命令有很多种不同细节使用方法,可以实现复杂的功能,记录几种在此,方便以后查询.    :s/vivian/sky/ 替换当前行第一个 vivian ...

  6. OpenLayers Map理解

    1,视口坐标的原点在左上角,水平向右为x轴正向,垂直向下为y 轴正向:2,地图坐标原点为初始图层的中心点,水平向右为x轴正向,垂直向上为y轴正向:3,视口中心点永远与地图中心点重合,不一定与瓦片中心点 ...

  7. rt—移植笔记1

    将rtt源码往stm32f407移植的时候,源码串口打印引脚设置有误,以下是源码引脚配置. 以下是原理图 可见配置有误.

  8. 学校系统快速js代码

    var select_arr=document.getElementById("iframeautoheight").contentWindow.document.getEleme ...

  9. arp命令

    地址解析协议ARP用于将IP地址解析成MAC地址.当把数据包从一个计算机发送到另一个计算机的时候,计算机或路由器使用ARP请求来确定下一跳的MAC地址. MAC地址用于按跳发送数据包,直到达到最终目的 ...

  10. DHCP服务器原理

    DHCP服务器   port:67 DHCP 这个服务可以自动的分配 IP 与相关的网络参数给客户端, 来提供客户端自动以服务器提供的参数来设定他们的网络   12.1 DHCP 运作的原理      ...