time limit per test1 second

memory limit per test256 megabytes

inputstandard input

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

一个比较坑的题,自己仔细推一下。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <set>
#include <map>
#include <list>
#include <vector>
#include <functional>
#include <algorithm>
using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef pair<int,int>PII; typedef vector<int>VI; typedef vector<LL>VL; const int INF = 0x3f3f3f3f; const double eps = 1e-6; const double Pi = acos(-1.0); int main()
{
ULL n,a,b,c; cin>>n>>a>>b>>c; if(a>n&&b>n)
{
cout<<0<<endl;
}
else if(a<=n&&b>n)
{
cout<<n/a<<endl;
}
else if(a>n&&b<=n)
{
cout<<(n-c)/(b-c)<<endl;
}
else{ if(a<=b-c)
{
cout<<n/a<<endl;
}
else
{
ULL ans = (n-c)/(b-c);
cout<<ans + (n-(ans*(b-c)+c)+c)/a<<endl;
}
}
return 0;
}

Codeforces Round #342 (Div. 2)-A. Guest From the Past的更多相关文章

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

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

  3. Codeforces Round #342 (Div. 2)

    贪心 A - Guest From the Past 先买塑料和先买玻璃两者取最大值 #include <bits/stdc++.h> typedef long long ll; int ...

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

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

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

  7. Codeforces Round #342 (Div. 2) A

    A. Guest From the Past time limit per test 1 second memory limit per test 256 megabytes input standa ...

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

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

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

随机推荐

  1. Qt在pro文件中加入带空格的路径(使用$$quote关键字)

    LIBS += -L$$quote(C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib) INCLUDEPATH += $$quote(C: ...

  2. SQL学习整理_1

    数据库是保存表和其他相关SQL结构的容器. 列是存储在表中的一块同类型数据. 行是一组能够描述某个事物的列的集合. SQL不区分大小写,但建议命令采用大写,表名采用小写,便于读写. 建立数据库 CRE ...

  3. 10个核心的Linux面试问题与答案

    http://www.geekfan.net/8571/ compgen ­-c,可以打印出所有支持的命令列表使用Linux 命令dirs可以将当前的目录栈打印出来.使用linux命令 ’disown ...

  4. anjularjs常用的内置方法

    1.$apply anjularjs通过$apply方法去执行脏检查,及时告诉model绑定变量更新. 示例:定义一个date变量显示在页面上,它的控制器是firstCtrl,这个date变量有一个时 ...

  5. spring 另开线程时的注入问题

    spring web项目在启动的时候,就会完成各种组件的注入.在工作的过程中,遇到了这样一个问题: 一个serviceA中要新开一个线程来执行一项任务(假定这个任务是ClassA).ClassA中要用 ...

  6. iOS程序中的内存分配 栈区堆区全局区

    在计算机系统中,运行的应用程序的数据都是保存在内存中的,不同类型的数据,保存的内存区域不同.一.内存分区 栈区(stack) 由编译器自动分配并释放,存放函数的参数值,局部变量等.栈是系统数据结构,对 ...

  7. 分享 rabbitMQ入门详解

    原文地址http://blog.csdn.net/cugb1004101218/article/details/21243927 目录(?)[-] rabbitMQ说明文档 rabbitMQ是什么 消 ...

  8. vim - copy/paste a word

    1. http://stackoverflow.com/questions/7797068/copying-a-word-and-pasting-over-a-word viwp - visually ...

  9. vs2010项目使用vs2013编译报错 无法打开包括文件:“winapifamily.h”

    我的老项目是vs2010下的项目.最近安装vs2013后,打开sln解决方案,调试运行报错 C:\Program Files (x86)\Windows Kits\8.0\Include\um\win ...

  10. SqlServer数据库空间使用情况常用命令

    --最简单的办法就是使用SSM客户端,报表查看 --查询数据文件的空间情况 dbcc showfilestats --查询日志文件的空间情况 dbcc sqlperf(logspace) --查询te ...