Codeforces 740A. Alyona and copybooks 模拟
1 second
256 megabytes
standard input
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.
The only line contains 4 integers n, a, b, c (1 ≤ n, a, b, c ≤ 109).
Print the minimum amount of rubles she should pay to buy such number of copybooks k that n + k is divisible by 4.
1 1 3 4
3
6 2 1 1
1
4 4 4 4
0
999999999 1000000000 1000000000 1000000000
1000000000
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 模拟的更多相关文章
- CodeForces 740A Alyona and copybooks
完全背包. 直接做个背包容量为$100000$的完全背包,这样就可以避免繁琐的分类讨论了. #pragma comment(linker, "/STACK:1024000000,102400 ...
- 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 ...
- CodeForces.158A Next Round (水模拟)
CodeForces.158A Next Round (水模拟) 题意分析 校赛水题的英文版,坑点就是要求为正数. 代码总览 #include <iostream> #include &l ...
- Codeforces E. Alyona and a tree(二分树上差分)
题目描述: Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- 【20.23%】【codeforces 740A】Alyona and copybooks
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Codeforces 740C. Alyona and mex 思路模拟
C. Alyona and mex time limit per test: 2 seconds memory limit per test: 256 megabytes input: standar ...
- Codeforces 747C:Servers(模拟)
http://codeforces.com/problemset/problem/747/C 题意:有n台机器,q个操作.每次操作从ti时间开始,需要ki台机器,花费di的时间.每次选择机器从小到大开 ...
- CodeForces 682A Alyona and Numbers (水题)
Alyona and Numbers 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/A Description After fi ...
- 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 ...
随机推荐
- php工作笔记4-mysql笔记1
1.Mysql中数值的长度和最大值是没有关系的,它仅仅只代表了数据的宽度,比如:int(4)和int(8)可以存储的数据长度是一样的,她两的大小都是4Byte, 在存储上数据的时候比如Int(4) | ...
- HUSTOJ搭建实录
要做一个MOOC平台,要求有在线编程功能,想偷个懒,于是用了HUSTOJ...... 系统:Ubuntu14.04 Kylin 步骤: 一.搭建服务器和相应环境 apache2: sudo apt-g ...
- 代理模式(Proxy pattern)
代理模式(proxy pattern):作用:为其他对象提供一种代理,以控制对这个对象的访问.代理对象在客户端对象和目标对象之间起中介的作用. 代理模式涉及到的角色: 抽象角色:声明真实对象和代理对象 ...
- Linux 查找文件
find 查找目录 -name "文件名"find / -name "php.ini"locate 文件名locate php.ini 一:locate命令 l ...
- adb无法使用,提示error: unknown host service的解决办法
此时,需要辨别电脑的5037端口被哪个应用程序占用的方法:(使用adb时需要5037端口是空闲的) 1. 打开命令行,输入命令:netstat -ano |findstr "5037&quo ...
- 获取HTML
public class GetHtml { public string GetWebRequest(string url) { Uri uri = new Uri(url); WebRequest ...
- 犀利点评:csdn某文<第一次创业还是失败了---分享失败的经验>
今天上午在csdn看了一篇创业文,突然想无节操的做一下点评. 原文详细地址如下:http://blog.csdn.net/android_tutor/article/details/9815801 以 ...
- linux一些目录功能
(1)/etc ----存放配置文件和子目录 (2)/dev -----是linux的外设文件,dev是devxe(设备)的缩写,在这个目录下存放的是所有linux的外设文件,.在li ...
- Android Studio启动模拟器
创建模拟器时出现vt x is disabled in bios 出现错误提示:"Intel HAXM is required to run this AVD,VT-x is disable ...
- Spark 读取HBase和SolrCloud数据
Spark1.6.2读取SolrCloud 5.5.1 //httpmime-4.4.1.jar // solr-solrj-5.5.1.jar //spark-solr-2.2.2-20161007 ...