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\) 个。分类讨论:

  • 如果放 \(3\) 个,则必须满足 \(\frac{\sqrt{3}}{2}r+r\le h'+r\),即 \(\frac{\sqrt{3}}{2}r\le h'\)。此时三个球的球心构成等边三角形。
  • 如果放 \(2\) 个,则两个球的球心必须在半圆形直径以下,即 \(\frac{r}{2}\le h'\)
  • 否则只能且一定放 \(1\) 个球(半圆形完全没有占用,肯定放得下)。
#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;
}
posted @ 2025-09-12 08:15  FormulaOne  阅读(19)  评论(0)    收藏  举报