传送门

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. String.Empty、null、“” 区别

    概念准备: 1.引用类型是将对象是实际数据保存在堆中, 将对象在堆中的地址保存在栈中. 2.值类型直接将实际数据存放在堆中,不会将对象在堆中的地址保存在栈中. 一.String.Empty和" ...

  2. IntelliJ IDEA 配置运行程序

    IntelliJ IDEA 对于Javaer开发来说还是很nice的,就是第一次用可能配置项有点生疏,这里就记录一下IntelliJ IDEA 配置运行程序. 1. 点击Edit Config... ...

  3. linux环境变量的设置

    linux中环境变量分为系统环境变量和用户环境变量(和window中一样),系统环境变量对所有系统用户都有效,用户环境变量只对当前用户有效,我们以ubuntu为例说明 用户环境变量 用户环境变量通常存 ...

  4. linux中文件(档案)和目录的RWX权限意义

    1 权限对文件的意义 权限对文件的意义很好理解,下面我们看看权限对目录的意义. 2 权限对目录的意义 档案是存放实际资料的所在,那么目录主要是储存啥玩意啊?目录主要的内容在记录档名清单,档名与目录有强 ...

  5. nginx转发会 默认忽略 headers 中name带”_”的

    昨天遇到一个很蛋疼的问题,在提供的一个 http api中,有定义了一个"X_AUTH_TOKEN"自定义head,可是请求这个api时带上"X_AUTH_TOKEN&q ...

  6. 添加文件到HDFS的集中缓存

    需求是这样的,有一些文件,需要常驻内存,提高读取效率的情况下,可以使用HDFS的缓存机制进行预先缓存 先添加POOL,然后添加需要缓存的文件即可 hdfs cacheadmin  -.tar.gz - ...

  7. [django]django+post+ajax+highcharts使用方法

    直接代码展示: view.py文件代码 from django.http import JsonResponse #django ajax部分 def ajax_kchart(request): ti ...

  8. [django]Django站点admin支持中文显示和输入设置

    正文: Django站点admin支持中文输入设置,操作如下: 1 需要确定的你的数据库的client客户端和服务端的编码设置为utf-8,如果不是,请将其设置成utf-8编码,我采用mysql,详情 ...

  9. HDU 1848 Fibonacci again and again【SG函数】

    对于Nim博弈,任何奇异局势(a,b,c)都有a^b^c=0. 延伸: 任何奇异局势(a1, a2,… an)都满足 a1^a2^…^an=0 首先定义mex(minimal excludant)运算 ...

  10. 使用Ecplise git commit时出现"There are no stages files"

    异常   解决方案 进入Window--Preferences--Team--Git--Committing,反选下图红圈部分:   保存后即可出线我们熟悉的提交代码界面啦: