CF342C题解

· · 题解

显然,每一层恰好能放下两个球(事实上这也是最优的方案),那么下面一共可以放 \lfloor \frac{h}{r} \rfloor \times 2 个球,剩余 h - \lfloor \frac{h}{r} \rfloor \times r+r 的高度,记 h'=h-\lfloor \frac{h}{r} \rfloor\times r 为立方体部分剩余高度。最上面至少能放 1 个球,至多 3 个。分类讨论:

#include<iostream>
#include<cstdio>
using namespace std;
int main(){
    int h,r,ans=0;
    cin>>r>>h;
    ans=h/r;
    h-=ans*r;
    ans*=2;
    if((double)h*h>=(double)0.75*r*r)ans+=3;
    else if((double)h>=(double)0.5*r)ans+=2;
    else ans++;
    cout<<ans;
    return 0;
}