Codeforces Round #342 (Div. 2) A

时间:2022-09-04 12:59:31
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 &num;342 &lpar;Div&period; 2&rpar; D&period; Finals in arithmetic 贪心

    D. Finals in arithmetic 题目连接: http://www.codeforces.com/contest/625/problem/D Description Vitya is s ...

  2. Codeforces Round &num;342 &lpar;Div&period; 2&rpar; C&period; K-special Tables 构造

    C. K-special Tables 题目连接: http://www.codeforces.com/contest/625/problem/C Description People do many ...

  3. Codeforces Round &num;342 &lpar;Div&period; 2&rpar; B&period; War of the Corporations 贪心

    B. War of the Corporations 题目连接: http://www.codeforces.com/contest/625/problem/B Description A long ...

  4. Codeforces Round &num;342 &lpar;Div&period; 2&rpar; A - Guest From the Past 数学

    A. Guest From the Past 题目连接: http://www.codeforces.com/contest/625/problem/A Description Kolya Geras ...

  5. Codeforces Round &num;342 &lpar;Div&period; 2&rpar; E&period; Frog Fights set 模拟

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

  6. Codeforces Round &num;342 &lpar;Div&period; 2&rpar; D&period; Finals in arithmetic(想法题&sol;构造题)

    传送门 Description Vitya is studying in the third grade. During the last math lesson all the pupils wro ...

  7. Codeforces Round &num;342 &lpar;Div&period; 2&rpar; C&period; K-special Tables(想法题)

    传送门 Description People do many crazy things to stand out in a crowd. Some of them dance, some learn ...

  8. Codeforces Round &num;342 &lpar;Div&period; 2&rpar; B&period; 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 &num;342 &lpar;Div&period; 2&rpar; A&period; Guest From the Past(贪心)

    传送门 Description Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the detai ...

  10. Codeforces Round &num;342 &lpar;Div&period; 2&rpar;-B&period; War of the Corporations

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

随机推荐

  1. 关于闭包(closure)的一些概念

    和其他大多数现代编程语言一样,JS也采用词法作用域,也就是说,函数的执行依赖于变量作用域,这个作用域是在函数定义时决定的,而不是函数调用时决定的.为了实现这种词法作用域,JS函数对象的内部状态不仅包含 ...

  2. &lbrack;No000073&rsqb;C&num;直接删除指定目录下的所有文件及文件夹&lpar;保留目录&rpar;

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  3. &lbrack;技巧&rsqb;如何清除VS2008的最近打开项目

    )删除最近打开的文件 运行regedit,打开HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\FileMRUList 之后,在右边删除相应键 ...

  4. 【转】 CATransform3D 矩阵变换之立方体旋转实现细节

    原文网址:http://blog.csdn.net/ch_soft/article/details/7351896 第一部分.前几天做动画,使用到了CATransform3D ,由于没有学过计算机图形 ...

  5. -&lowbar;-&num;【CSS3】浏览器前缀

    前缀 浏览器 -khtml Konqueror(非常老的 Safari) -moz Firefox -o Opera -ms Internet Explorer -webkit Safari.Chro ...

  6. js中年份、月份下拉框

    <select id="year" style="width: 100px;"></select> <select id=&quo ...

  7. windows下安装mysql-5&period;7&period;11-winx64

    1.解压.   2.将『D:\Program Files\mysql-5.7.11-winx64\bin』加入系统环境变量.   3.修改my-default.ini.   4.初始化data目录,在 ...

  8. &commat;Async的简单用法总结

    前言: 在Java应用中,绝大多数情况下都是通过同步的方式来实现交互处理的:但是在处理与第三方系统交互的时 候,容易造成响应迟缓的情况,之前大部分都是使用多线程来完成此类任务,其实,在Spring 3 ...

  9. 检查URL的可用性脚本

    #!/bin/bash check_url() { HTTP_CODE=$(curl -o /dev/ -s -) ];then echo "Warning: $1 Access failu ...

  10. &lbrack;na&rsqb;&lbrack;dhcp&rsqb;dhcp细枝末节&amp&semi;dhcp防攻

    回顾了下,真是以前是一种感觉以后是一种感觉. 特点: 1.dhcp服务器上的配置的网关不一定要有这个ip 2.dhcp服务只是个类似数据库而已(如果不在一个lan). 3. 如果dhcp不在一个lan ...