Codeforces Round #342 (Div. 2) A. Guest From the Past(想法)

地址:http://codeforces.com/contest/625/problem/A

第一次碰到wa了这么多次的div2A题 TAT

题意简单,有n块钱,要买东西,要买的数量最多。两种买法,一种就是a块钱一个,另一种就是b块钱买一个,买完了他回送你c块

那么实际上就是两种情况,一种是用A plan买更优,一种是用B plan买更优,用a买的个数很清楚,就是n/a。难算的是用b买。

那么我们这样思考,假设他每次买b找回c,到最后一次刚好剩下b块,把钱用光了,那么最后就找回了c块。这样的情况买的个数是(n-c)/(b-c),每次用掉的是差价。然而仔细想想,这样的计算方法,实际只是影响最后剩下的钱,用b买的个数就是(n-c)/(b-c)。

把这个公式想到就好做了。

#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<map>
#include<iostream>
#include<vector>
#include<cstdlib>
#include<cmath>
#include<stack>
#include<ctime>
#include<cctype>
#include<set>
#include<algorithm>
using namespace std;
const int INF=1e9+7;
typedef pair<int,int> pii;
typedef long long ll;
ll n,a,b,c;
inline ll getfroma(ll x){
    return x/a;
}
inline ll getfromb(ll x){
    if(x<b)return 0;
    return (x-c)/(b-c);
}
int main(){
//    freopen("D://input.txt","r",stdin);
    scanf("%I64d%I64d%I64d%I64d",&n,&a,&b,&c);
    ll ans=getfroma(n)+getfromb(n%a);//all from a+last from b
    ll gb=getfromb(n);
    ans=max(ans,gb+getfroma(n-gb*(b-c)));//all from b+last from a
    printf("%I64d\n",ans);
//  printf("%.3f\n",(double)clock()/CLOCKS_PER_SEC);
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值