【20.23%】【codeforces 740A】Alyona and copybooks
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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 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.
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/problemset/problem/740/A
【题解】
题意:让你加上若干个1,2,3;然后使得n变成n+k;要求n+k能被4整除,并且数字1、2、3都有相应的价格,问价格最小是多少;
做法:
我是先用二分搞出比n大的第一个能被4整除的数字是多少->ans*4;
然后用ans*4-n;得到now;
然后根据now的大小分情况讨论;
now==0,不用数字输出0;
now==1,1个a、或b+c=5,或3个c->9;
now==2,1个b,两个a或2个c都行
now==3,3个a,||1个c,||a+b;
因为a,b,c大小可能很悬殊,所以几种情况都要比较;
【完整代码】
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int MAXN = 1e9;
LL n,a,b,c;
int main()
{
//freopen("F:\\rush.txt","r",stdin);
cin >> n >> a >> b >> c;
LL now = 0;
LL l = 0,r = MAXN,ans = 0;
while (l <= r)
{
LL m = (l+r)>>1;
if (4*m>=n)
{
ans = m;
r = m-1;
}
else
l = m+1;
}
if (4*ans == n)
puts("0");
else
{
LL now = ans*4-n;
LL temp = 0;
if (now==1)
{
temp = a;
temp = min(temp,b+c);
temp = min(temp,c*3);
}
else
if (now == 2)
{
temp = b;
temp = min(temp,a*2);
temp = min(temp,2*c);
}
else
if (now ==3)
{
temp = c;
temp = min(temp,a*3);
temp = min(temp,b+a);
}
cout << temp << endl;
}
return 0;
}
【20.23%】【codeforces 740A】Alyona and copybooks的更多相关文章
- 【 BowWow and the Timetable CodeForces - 1204A 】【思维】
题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...
- 【23.26%】【codeforces 747D】Winter Is Coming
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【23.33%】【codeforces 557B】Pasha and Tea
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【23.39%】【codeforces 558C】Amr and Chemistry
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【30.23%】【codeforces 552C】Vanya and Scales
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【16.23%】【codeforces 586C】Gennady the Dentist
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【20.51%】【codeforces 610D】Vika and Segments
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【77.78%】【codeforces 625C】K-special Tables
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- 【codeforces 750A】New Year and Hurry
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
随机推荐
- UVALive 6527 Counting ones dfs(水
题目链接:点击打开链接 #include <cstdio> #include <vector> using namespace std; typedef long long l ...
- 兔子--ps中的基本工具总结(ps cs5)
矩形选框工具 椭圆选框工具 单行选框工具 单列选框工具 移动工具 套索工具柜 多边形套索工具 磁性套索工具 魔棒工具 高速选择工具 裁剪工具 切片工具 切片选择工具 吸管工具 颜色取样器工具 标尺工具 ...
- 将bat批处理命令文件固定到任务栏
将bat批处理命令文件固定到任务栏第一种方法:使用链接工具http://www.xstui.com/read/3451.在任务栏点击右键,移动到工具栏,勾选链接工具2.你会在通知栏左侧看到链接字样,将 ...
- 1.3 Quick Start中 Step 3: Create a topic官网剖析(博主推荐)
不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ Step 3: Create a topic Step 3: 创建一个主题(topi ...
- 用C#生成随机中文汉字验证码的基本原理
前几天去申请免费QQ号码,突然发现申请表单中的验证码内容换成了中文,这叫真叫我大跌眼镜感到好笑,Moper上的猫儿们都大骂腾讯采用中文验证码.^_^ 我不得不佩服腾讯为了防止目前网络上横行的QQ号码 ...
- CentOS 7最小化安装图解
一.环境介绍: win10 x64安装VMware® Workstation 14 Pro(版本:14.1.2 build-8497320) 二.安装CentOS 1.新建虚拟机 打开虚拟机,主页,创 ...
- mysql-5.7.19-winx64服务无法启动解决方案
解压mysql压缩包时没有data文件夹,不要手动创建,在cmd下直接运行命令: mysqld –initialize-insecure,data文件夹会自动生成,注意单词千万不要拼错,不要写成–in ...
- HTML基础第七讲---框架
转自:https://i.cnblogs.com/posts?categoryid=1121494 框架(Frame)也就是所谓的分割窗口.分割画面.框窗效果(还真是五花八门),这个技巧在运用上问题比 ...
- JSP学习 —— 开篇:JSP,servlet容器,Tomcat,servlet容器之间的关系
JSP(JAVA SERVER PAGE)的缩写,其本身就是servlet的简化,是一种动态网页标准,其特点是在HTML代码中嵌入JAVA代码,JSP标签或用户标签来生成网页.至于它为什么会出现,主要 ...
- [Angular] Using the Argon 2 Hashing Function In Our Sign Up Backend Service
Which hash algorithom to choose for new application: https://www.owasp.org/index.php/Password_Storag ...