Codeforces Round #342 (Div. 2) A
1 second
256 megabytes
standard input
standard output
Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much more complicated.
Kolya is hungry, so he went to the nearest milk shop. In 2084 you may buy kefir in a plastic liter bottle, that costs a rubles, or in glass liter bottle, that costs b rubles. Also, you may return empty glass bottle and get c (c < b) rubles back, but you cannot return plastic bottles.
Kolya has n rubles and he is really hungry, so he wants to drink as much kefir as possible. There were no plastic bottles in his 1984, so Kolya doesn't know how to act optimally and asks for your help.
First line of the input contains a single integer n (1 ≤ n ≤ 1018) — the number of rubles Kolya has at the beginning.
Then follow three lines containing integers a, b and c (1 ≤ a ≤ 1018, 1 ≤ c < b ≤ 1018) — the cost of one plastic liter bottle, the cost of one glass liter bottle and the money one can get back by returning an empty glass bottle, respectively.
Print the only integer — maximum number of liters of kefir, that Kolya can drink.
10
11
9
8
2
10
5
6
1
2
In the first sample, Kolya can buy one glass bottle, then return it and buy one more glass bottle. Thus he will drink 2 liters of kefir.
In the second sample, Kolya can buy two plastic bottle and get two liters of kefir, or he can buy one liter glass bottle, then return it and buy one plastic bottle. In both cases he will drink two liters of kefir.
题意:塑料瓶牛奶a元 玻璃瓶牛奶b元 玻璃瓶能够卖c元 现有n元 问最多能喝多少瓶牛奶
题解:两种情况 1.优先买塑料瓶牛奶 ans1
2.优先买玻璃瓶牛奶 ans2
注意细节分析!!
#include<iostream>
#include<cstdio>
#define LL __int64
using namespace std;
int main()
{
LL a,b,c,n,ans1=0,ans2=0;
scanf("%I64d%I64d%I64d%I64d",&n,&a,&b,&c);
LL exm=0;
exm=n;
ans1=exm/a;
exm=exm-ans1*a;
if(exm>=b)//当前钱数大于b元
{
ans1=ans1+(exm-b)/(b-c);//细节
ans1++;
}
if(n>=b)
{
ans2=(n-b)/(b-c);
ans2++;
n=n-ans2*(b-c);
}
ans2+=n/a;
if(ans1>ans2)
printf("%I64d\n",ans1);
else
printf("%I64d\n",ans2);
return 0;
}
Codeforces Round #342 (Div. 2) A的更多相关文章
- Codeforces Round #342 (Div. 2) D. Finals in arithmetic 贪心
D. Finals in arithmetic 题目连接: http://www.codeforces.com/contest/625/problem/D Description Vitya is s ...
- Codeforces Round #342 (Div. 2) C. K-special Tables 构造
C. K-special Tables 题目连接: http://www.codeforces.com/contest/625/problem/C Description People do many ...
- Codeforces Round #342 (Div. 2) B. War of the Corporations 贪心
B. War of the Corporations 题目连接: http://www.codeforces.com/contest/625/problem/B Description A long ...
- Codeforces Round #342 (Div. 2) A - Guest From the Past 数学
A. Guest From the Past 题目连接: http://www.codeforces.com/contest/625/problem/A Description Kolya Geras ...
- Codeforces Round #342 (Div. 2) E. Frog Fights set 模拟
E. Frog Fights 题目连接: http://www.codeforces.com/contest/625/problem/E Description stap Bender recentl ...
- Codeforces Round #342 (Div. 2) D. Finals in arithmetic(想法题/构造题)
传送门 Description Vitya is studying in the third grade. During the last math lesson all the pupils wro ...
- Codeforces Round #342 (Div. 2) C. K-special Tables(想法题)
传送门 Description People do many crazy things to stand out in a crowd. Some of them dance, some learn ...
- Codeforces Round #342 (Div. 2) B. War of the Corporations(贪心)
传送门 Description A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Go ...
- Codeforces Round #342 (Div. 2) A. Guest From the Past(贪心)
传送门 Description Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the detai ...
- Codeforces Round #342 (Div. 2)-B. War of the Corporations
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
随机推荐
- python学习笔记02 --------------基础数据类型
python的基本数据类型: 1.基本数据 1.1. 数字类型 1.1.1 整数 int int() #将括号内内容转化为整数类型. 1.1.2 浮点数 float 1.1.3 复 ...
- 原生js实现轮播图原理
轮播图的原理1.图片移动实现原理:利用浮动将所有所有照片依次排成一行,给这一长串图片添加一个父级的遮罩,每次只显示一张图,其余的都隐藏起来.对图片添加绝对定位,通过控制left属性,实现照片的移动. ...
- CSP201609-1:最大波动
引言:CSP(http://www.cspro.org/lead/application/ccf/login.jsp)是由中国计算机学会(CCF)发起的"计算机职业资格认证"考试, ...
- DeepLearning Intro - sigmoid and shallow NN
This is a series of Machine Learning summary note. I will combine the deep learning book with the de ...
- 6.hdfs的存储过程
1.hdfs 怎么存储 切割存储 2. 为何每块是128m 与io读写速度有关,一般人的接受速度1s中,而磁盘的读写速度为100m/s,在读取文件时候需要硬盘寻找地址,一般读懂速度和寻找之间的比例是1 ...
- Centos6设置DNS
通过编辑 vi /etc/resolv.conf 设置首选DNS和次要DNS.如下,排在前面的就是首选DNS,后面一行就是次要的DNS服务器DNS vi /etc/resolv.conf namese ...
- codeforces 359E Neatness(DFS+构造)
Simon loves neatness. So before he goes to bed, Simon wants to complete all chores in the house. Sim ...
- 详解实现Android中实现View滑动的几种方式
注: 本文提到的所有三种滑动方式的完整demo:ScrollDemo 1. 关于View我们需要知道的 (1)什么是View? Android中的View类是所有UI控件的基类(Base class) ...
- 【week7】psp
本周psp 项目 内容 开始时间 结束时间 中断时间 净时间 2016/10/31 技术学习 看向数据库传入数据的代码 18:00 21:00 45 135 psp记录 将psp记录进电脑 21:20 ...
- python爬虫 赶集网
#coding=utf-8import requestsfrom lxml import etreefrom sqlalchemy import create_enginefrom sqlalchem ...