CF342C题解
Aurora_Lights · · 题解
显然,每一层恰好能放下两个球(事实上这也是最优的方案),那么下面一共可以放
- 如果放
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;
}