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 ...
随机推荐
- mvc 3 Mvc 4 使用Forms 登录验证随笔一
前言 本人虽然做 .Net 也有五年有余,可是没什么大才,总是干些打杂的活,技术很少差劲呀.以前不管是做内部管理系统,还是企业平台,保存用户登录信息用的都是Session,也许是从一开始就接触Sess ...
- Linux图形&命令行界面切换
1.实时切换 1.1 命令行->图形 startx 1.2 图形->命令行 Ctrl+Alt+F1--F6 2.启动默认 2.1 启动进入命令行 修改/etc/inittab文件 &quo ...
- spring_异常提示1
nested exception is java.lang.NoClassDefFoundError: org/springframework/aop/TargetSource ------- 缺少j ...
- 移动到web整理
meta基础知识 H5页面窗口自动调整到设备宽度,并禁止用户缩放页面 <meta name="viewport" content="width=device-wid ...
- [SharePoint 2013] Set value for people editor with JSOM
function PeoplePicker() { this.context = null; this.web = null; this.currentUser = null; this.parent ...
- MVC中的成员资格,授权,安全性
使用 Authorize 特性登录 Authorize 是 ASP.NET MVC 自带的默认授权过滤器, 可用来限制用户对操作方法的访问. 保护控制器操作 Authorize 特性在表单身份验证和 ...
- Redhat 7 或者 CentOS 7 密码破解
1.在如下界面按 e 2.在 linux16 这一行的最后面添加 rd.break,然后按 ctrl + x 进入单用户模式 3.以读写的方式重新挂载 sysroot 4.切换到 sysroot 目录 ...
- eclipse tomcat 集成
1. 下载 Tomcat 作者选择的是 Tomcat6,下载地址:http://tomcat.apache.org/download-60.cgi,选择绿色版的 zip 进行下载(目前最 ...
- UVALive 7147 World Cup(数学+贪心)(2014 Asia Shanghai Regional Contest)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=6 ...
- cassandra.yaml介绍
cluster_name 集群的名字,默认情况下是TestCluster.对于这个属性的配置可以防止某个节点加入到其他集群中去,所以一个集群中的节点必须有相同的cluster_name属性. list ...