A. Guest From the Past(思维+数学)

https://codeforces.com/contest/625/problem/A


思路:依然是青蛙跳井。

不过这题多了几个小讨论。

开始全部买a

最后一次的钱接着买b或者全买a

#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e5;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL H;cin>>H;
  LL a,b,c;cin>>a>>b>>c;
  LL ans0=H/a;///开始全部买a
  LL ans=0;
  ///只能拿一次的特判
  if(H+(c-b)<b){
    if(H>=b) ans++,H-=abs(c-b);
    ans+=H/a;
  }
  else if(H-b>=0){
    LL H1=H-b;
    LL k=(H1+abs(c-b)-1)/abs(c-b);
    H-=k*abs(c-b);
    ans+=k;///此时再买b就会死
    ///再买b最后一次
    LL res1=0;
    LL H2=H;
    res1+=H2/b; H2-=res1*abs(b-c);
    res1+=H2/a;
    ///最后一次直接都买a
    LL res2=0;
    LL H3=H;
    res2+=H3/a;
    ans+=max(res1,res2);
  }
  cout<<max(ans,ans0)<<"\n";
return 0;
}

猜你喜欢

转载自blog.csdn.net/zstuyyyyccccbbbb/article/details/114920929