题解 | 小红杀怪

小红杀怪

https://www.nowcoder.com/practice/d337370cc83146ad9a02ea554fd2594b

void solve(){
    int a,b,x,y;cin>>a>>b>>x>>y;
    int ans=inf;
    for(int i=0;i<=20;i++){
        for(int j=0;j<=20;j++){
            int restA=a,restB=b,iNeed=0;
            restA-=j*y,restB-=j*y;
            if(restA>0)iNeed+=(restA+x-1)/x;
            if(restB>0)iNeed+=(restB+x-1)/x;
            if(iNeed<=i)ans=min(ans,i+j);
        }
    }
    cout<<ans<<endl;
}

考虑到每种攻击最多进行20次,因此可以选择枚举所有选择的组合,判断其能否同时击杀两个怪

全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务