A. Guest From the Past
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

Print the only integer — maximum number of liters of kefir, that Kolya can drink.

Sample test(s)
Input
10
11
9
8
Output
2
Input
10
5
6
1
Output
2
Note

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的更多相关文章

  1. 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 ...

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

  3. 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 ...

  4. 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 ...

  5. Codeforces Round #342 (Div. 2) E. Frog Fights set 模拟

    E. Frog Fights 题目连接: http://www.codeforces.com/contest/625/problem/E Description stap Bender recentl ...

  6. 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 ...

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

  8. 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 ...

  9. 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 ...

  10. Codeforces Round #342 (Div. 2)-B. War of the Corporations

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

随机推荐

  1. Navicat和DBeaver的查询快捷键

    1.Navicat for MySQL(连接MySQL数据库的工具) ctrl + r 执行查询页中所有的sql语句 ctrl + shift + r 只运行选中的sql语句 2.DBeaver(支持 ...

  2. python基本数据类型——集合

    集合 无序可变序列,集合中元素不允许重复,即每个元素都是唯一的 集合中的元素按照升序排列 # 创建集合 >>aset = set([0,2,4,5,7,2,3,5,9,0]) >&g ...

  3. (转) GEM透视阴影贴图

    转载:小道 透视阴影贴图(Perspective Shadow Maps, PSMs)是由Stamminger和Drettakis在 SIGGRAPH 2002上提出的一种阴影贴图(Shadow Ma ...

  4. Linux的基础预备知识

       Linux下一切皆文件 1.root@mk-virtual-machine:/home/mk#   root:该位置表示当前终端登录的用户名 mk-virtual-machine:/home/m ...

  5. matconv-GPU 编译问题

    如出现以下错误: 1 error detected in the compilation of "C:/Users/Justin/AppData/Local/Temp/tmpxft_0000 ...

  6. windows10下git一些问题

    windows10下安装git 找不到ssh解决办法 解决办法是: 输入下列命令,一路回车 $ ssh-keygen -t rsa -C “邮箱地址” 若执行ssh-add /path/to/xxx. ...

  7. C#调用mingw的so库时无法加载DLL###.so 找不到指定的模块

    使用C#调用mingw的so,报了c# 无法加载DLL“###.so”,: 找不到指定的程序. (异常来自 HRESULT:0x8007007E)开始以为是dll路径问题,使用全路径确认正确后仍然无法 ...

  8. Mybatis中resultMap与resultType区别

    MyBatis中在查询进行select映射的时候,返回类型可以用resultType,也可以用resultMap,resultType是直接表示返回类型的,而resultMap则是对外部ResultM ...

  9. HDU 4169 Wealthy Family(树形DP)

    Problem Description While studying the history of royal families, you want to know how wealthy each ...

  10. 基于angular+bower+glup的webapp

    一:bower介绍 1:全局安装安装bower cnpm i -g bower bower常用指令: bower init //初始化文件 bower install bower uninstall ...