传送门

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. sizeof与strlen的区别

    1 sizeof是操作符,而strlen是库函数: 2 sizeof的参数可以为任意变量或类型,而strlen必须以char*做参数,且字符串必须以‘/0’结尾: 3 数组名用作sizeof参数时不会 ...

  2. SQL Like模糊查询一些小知识

    模糊查询: where mc like '值':返回值等同于where mc ='值' where mc like '%值':匹配 名称是 '*值'(以“值”作为结尾)的所有数据,*表示任何值任何长度 ...

  3. [Java入门笔记] 面向对象三大特征之:封装

    了解封装 什么是封装? 在Java的面向对象程序设计中,有三大基本特征:封装.继承和多态.首先我们先来看看封装: 在Java的面对对象程序设计中,封装(Encapsulation)是指一种将函数功能实 ...

  4. 关于Oracle报“ORA-12514 TNS 监听程序当前无法识别连接描述符中请求服务”错误

    关于Oracle报“ORA-12514 TNS 监听程序当前无法识别连接描述符中请求服务”错误原因:listener.ora中没有指定监听服务器名. 如下是解决思路: 尝试1.通过重启服务的方式启动数 ...

  5. Ajax的笔记

    Ajax指异步JavaScript及XML(Asynchronous JavaScipt And XML),是一种异步交互式网页开发技术,用于创建快速动态网页.与服务器进行少量数据交换中,Ajax可以 ...

  6. oh-my-zsh主题

    什么是ZSH Zsh和bash一样,是一种Unix shell,但大多数Linux发行版本都默认使用bash shell.但Zsh有强大的自动补全参数.文件名.等功能和强大的自定义配置功能. 一.安装 ...

  7. Python class and function json

    # coding=utf-8 __author__ = 'student' ''' how to define a class how to extend a class how to make a ...

  8. [WPF系列]-数据邦定之DataTemplate 根据对象属性切换模板

      引言 书接上回[WPF系列-数据邦定之DataTemplate],本篇介绍如何根据属性切换模板(DataTemplate)   切换模板的两种方式:   使用DataTemplateSelecto ...

  9. 按日子来干活——第一个Blog Day&Happy Day

    今天(周一)看到一位同仁的生活规划,感觉挺适合我,实践一下,就theo&tools day+code day+blog day,间歇性有happy day嘛~ blog day这样做,一篇bl ...

  10. 传输层协议TCP和UDP

    本文力图简洁,让读者对TCP和UDP有个初步的认知.闲话少说,现在开始吧.TCP和UDP都是传输层的协议.TCP通过三次握手建立可靠连接,对未送达的消息重新进行发送.UDP不建立连接而直接发送,对未送 ...