http://codeforces.com/contest/625/problem/A
题意给n块钱买牛奶
塑料盒牛奶价格 a
玻璃盒牛奶价格 b
回收玻璃盒的价格 c
问你最多能买多少盒牛奶
贪心,看 a 便宜还是 d=b-c便宜
如果a便宜,就先尽可能买a,剩下的钱买b
否则,先尽可能买b,最后买a
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iostream>
using namespace std;
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
const __int64 inf=2147483647;
const double pi=acos(-1.0);
double eps=0.000001;
__int64 min(__int64 a,__int64 b)
{return a<b?a:b;}
__int64 max(__int64 a,__int64 b)
{
return a<b?b:a;
}
__int64 maxx=0;
__int64 n,a,b,c;
int main()
{
scanf("%I64d",&n);
scanf("%I64d%I64d%I64d",&a,&b,&c);
__int64 d=b-c;
__int64 cun=0;
if(d<a) //如果买b的代价(d)比较小,则贪心买多一点b
{
if (n>b)
{
cun+= (n-b)/d; //先留下一个b,以免出现无法购买的情况
n=b+(n-b)%d;
}
if (n>=b)
{
cun++; //买下最后一个b
n-=d;
}
cun+=n/a; //剩下的都去买a
}
else //买a的代价比较小,贪心买a
{
cun+=n/a;
n=n%a;
if (n>b) //剩余的钱如果可以买,则按上面的方法,尽可能买b
{
cun+= (n-b)/d;
n=b+(n-b)%d;
}
if (n>=b)
{
cun++;
n-=d;
}
}
printf("%I64d\n",cun);
return 0;
}