Codeforces Round #342 (Div. 2)-A. Guest From the Past
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的更多相关文章
- 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) 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)
贪心 A - Guest From the Past 先买塑料和先买玻璃两者取最大值 #include <bits/stdc++.h> typedef long long ll; int ...
- 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
A. Guest From the Past time limit per test 1 second memory limit per test 256 megabytes input standa ...
- 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 ...
随机推荐
- Universal Link 笔记
如何实现Universal Link? 简单地说三步,1.把一个配置文件放在指定服务器根目录 2.在Xcode中设置AssociateDomain 3.安装app时,会根据Xcode中设置的Assoc ...
- css3知识
一.box-sizing 属性 规定两个并排的带边框的框 二.align-items (适用于父类容器上) 设置或检索弹性盒子元素在侧轴(纵轴)方向上的对齐方式. 值: flex-start:弹性盒子 ...
- vim - mark
Using markshttp://vim.wikia.com/wiki/Using_marks1. There is no visible indication of where marks are ...
- RabbitMQ模拟器使用方法
同事推荐了一个很好玩的RabbitMQ模拟器,记录一下简要使用方法. 模拟器地址 http://tryrabbitmq.com/ 使用方法: 直接将画框左面的图标拖进画图区,构建想要的拓扑图: 按住A ...
- (三) UART 串口通讯
UART : university asynchronous receiver and transmitter UART // 通用异步接收器和发送器 为什么要有串口:因为许多嵌入式设备没有显示屏 ...
- PeopleSoft Rich Text Boxes上定制Tool Bars
在使用PT8.50或在8.51时,你可能遇到过Rich-text编辑框.该插件使你能够格式化文本,添加颜色.链接.图片等等.下面是效果图: 如果页面中只有这么一个字段,该文本框就会有足够的空间来容 ...
- [转]一个用户SQL慢查询分析,原因及优化
来源:http://blog.rds.aliyun.com/2014/05/23/%E4%B8%80%E4%B8%AA%E7%94%A8%E6%88%B7sql%E6%85%A2%E6%9F%A5%E ...
- sp_MSforeachtable 与 sp_MSforeachdb
在MSSQL里有许多不公开的系统存储过程,其中可能常用的sp_MSforeachtable和sp_MSforeachdb有这2个.分别用于遍历某数据库的每个用户表.每个数据库. sp_MSforeac ...
- Html的智能表单
-新的输入类型 -email -url -number -range -Date pickers ( date ,month ,week, time , datetime ,datetime-loca ...
- 关于ibatis中mysql的@变量问题作用域、污染问题
搞了1天,过程不想多说,结论如下: ibatis.net 是有连接池的,用ab.exe 并发测试,可以测出默认的max连接数 ibatis.net的数据操作 xml 中可以用@变量,也就是 Sessi ...