传送门

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. Openstack api 学习文档 & restclient使用文档

    Openstack api 学习文档 & restclient使用文档 转载请注明http://www.cnblogs.com/juandx/p/4943409.html 这篇文档总结一下我初 ...

  2. ORACLE 9i 数据库体系结构图

    ORACLE 9i 的数据库体系结构图,非常的全面.系统.高屋建瓴的整体介绍了ORACLE 9i 的数据库体系结构.如果能全面了解.清晰梳理.深入掌握这些知识点,相信对你了解学习.深入研究ORACLE ...

  3. webapi 控制器接收POST参数时必须以对象的方式接收

    webapi    控制器接收POST参数时必须以对象的方式接收

  4. com.sun.xml.internal.ws.server.ServerRtException: Server Runtime Error: java.net.BindException: Cannot assign requested address: bind

    在发布 web service 时报错: Endpoint.publish(publishAddress, hl7MessageReveiver); com.sun.xml.internal.ws.s ...

  5. Linux – Usermod命令参数解析和实例说明

    usermod 命令修改系统帐户文件来反映通过命令行指定的变化 1. 首先看看usermod都是有哪些参数 [root@hxweb101 ~]$ usermod --help Usage: userm ...

  6. java操作hdfs实例

    环境:window7+eclipse+vmware虚拟机+搭建好的hadoop环境(master.slave01.slave02) 内容:主要是在windows环境下,利用eclipse如何来操作hd ...

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

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

  8. python爬虫学习(4) —— 手刃「URP教务系统」

    0. 本爬虫目标 模拟登陆URP教务系统 查询 本学期/历年 成绩 计算历年成绩的绩点 下面是一点废「私」话「货」: 一般情况,查询成绩大家会通过如下方式: 登陆信息门户 -> 转到教学空间 - ...

  9. GIF

  10. 理解ThreadLocal(之二)

    想必很多朋友对ThreadLocal并不陌生,今天我们就来一起探讨下ThreadLocal的使用方法和实现原理.首先,本文先谈一下对ThreadLocal的理解,然后根据ThreadLocal类的源码 ...