传送门

Description

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 ab 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 Input

101198
10561

Sample Output

2

2

思路

题意:

一种饮料有塑料和玻璃两种包装,购买塑料包装花费a元,购买玻璃包装花费b元,同时玻璃瓶子可以兑换c元(c < b ),塑料包装不能兑换,问n元最多购买多少瓶饮料

题解:

当b - c < a时,尽可能多的购买玻璃包装,否则尽可能多的购买塑料包装。

#include<bits/stdc++.h>
using namespace std;
typedef __int64 LL;

int main()
{
	LL n,a,b,c,tmp;
	scanf("%I64d%I64d%I64d%I64d",&n,&a,&b,&c);
	LL cnt = 0;
	LL d = b - c;
	if (d < a && n >= b)
	{
		n -= b;
		tmp = n / d;
		cnt += tmp;
		n -= tmp*d;
		LL dif = n + b;
		while (dif >= b)
		{
			tmp = dif/b;
			cnt += tmp;
			dif -= tmp*b;
			dif += tmp*c;
		}
		cnt += dif/a;
	}
	else
	{
		tmp = n/a;
		cnt += tmp;
		n -= tmp*a;
		LL dif = n;
		while (dif >= b)
		{
			tmp = dif/b;
			cnt += tmp;
			dif -= tmp*b;
			dif += tmp*c;
		}
	}
	printf("%I64d\n",cnt);
	return 0;
}

  

#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

ll judge(ll n, ll a, ll b, const ll c) {
	ll ans = 0;
	if (b - c < a && n >= b) {
		ans = (n - b) / (b - c) + 1;
		n -= (b - c) * ans;
	}
	ans += n / a;
	return ans;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll n, a, b, c;
	cin >> n;
	cin >> a >> b >> c;
	ll ans = judge(n, a, b, c);
	cout << ans << 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

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

  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 先买塑料和先买玻璃两者取最大值 #include <bits/stdc++.h> typedef long long ll; int ...

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

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

  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. Play Framework 完整实现一个APP(九)

    添加增删改查操作 1.开启CRUD Module 在/conf/application.conf 中添加 # Import the crud module module.crud=${play.pat ...

  2. native2ascii 使用说明

    native2ascii.exe 是Java的一个文件转码工具,是将特殊各异的内容转为用指定的编码标准文体形式统一的表现出来,它通常位于JDK_home\bin目录下,安装好Java SE后,可在命令 ...

  3. 使用memadmin可视化监视我们的memcache

    相信还是有很多项目使用memcache,可能有些人说有点out了,但是呢??? 项目上的东西不是你想换就能换的...谁都想多一事不如少 一事,大面积更换之后所面临的未知风险可能让你无法承受,但是呢, ...

  4. Google在KDD2013上关于CTR的一篇论文

    最近在做CTR,刚好Google在KDD发了一篇文章,讲了他们的一些尝试,总结一下: 先是一些公式的符号说明: 一.优化算法 CTR中经常用Logistic regression进行训练,一个常用的L ...

  5. spark streaming 与 kafka 结合使用的一些概念理解

    1. createStream会使用 Receiver:而createDirectStream不会,数据会通过driver接收. 2.createStream使用 Receiver 源源不断的接收数据 ...

  6. PHP 源码学习之线程安全

    从作用域上来说,C语言可以定义4种不同的变量:全局变量,静态全局变量,局部变量,静态局部变量. 下面仅从函数作用域的角度分析一下不同的变量,假设所有变量声明不重名. 全局变量,在函数外声明,例如,in ...

  7. linux中inode、软链接、硬链接

    1 软链接 linux中软链接理解成window中的快捷方式.创建软链接的命令 ln -s 源文文件或目录 目标文件或目录 2 硬链接 创建硬链接的命令如下 ln  源文文件或目录 目标文件或目录 3 ...

  8. mysql explain的使用(优化查询)

    explain显示了mysql如何使用索引来处理select语句以及连接表.可以帮助选择更好的索引和写出更优化的查询语句. 1.创建数据库 创建的sql语句如下: /* Navicat MySQL D ...

  9. Centos允许root远程登录设置

      以root权限执行 vi /etc/ssh/sshd_config 将 #PermitRootLogin yes 这一行的“#”去掉,修改为: PermitRootLogin yes 重启ssh服 ...

  10. postman使用之二:数据同步和创建测试集

    数据同步 启动postman 后在右上角可以登录账号,登录后就可以同步自己的api测试脚本,连上网在办公区在家都可以同步. 创建测试集 1.点击collections,点击add folder 2.c ...