codeforces 342C Cupboard and Balloons(公式题)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud
A girl named Xenia has a cupboard that looks like an arc from ahead. The arc is made of a semicircle with radius r (the cupboard's top) and two walls of height h (the cupboard's sides). The cupboard's depth is r, that is, it looks like a rectangle with base r and height h + rfrom the sides. The figure below shows what the cupboard looks like (the front view is on the left, the side view is on the right).
![](http://espresso.codeforces.com/0d3a8ee208fe4f3ad9899a205032d363d083f939.png)
Xenia got lots of balloons for her birthday. The girl hates the mess, so she wants to store the balloons in the cupboard. Luckily, each balloon is a sphere with radius . Help Xenia calculate the maximum number of balloons she can put in her cupboard.
You can say that a balloon is in the cupboard if you can't see any part of the balloon on the left or right view. The balloons in the cupboard can touch each other. It is not allowed to squeeze the balloons or deform them in any way. You can assume that the cupboard's walls are negligibly thin.
The single line contains two integers r, h (1 ≤ r, h ≤ 107).
Print a single integer — the maximum number of balloons Xenia can put in the cupboard.
1 1
3
1 2
5
2 1
2
考虑到从下往上开始摆的空间利用率高,于是只需要考虑最终的顶上还能否再塞进一个气球即可。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 //##################### 2 //Author:fraud 3 //Blog: http://www.cnblogs.com/fraud/ 4 //##################### 5 #include <iostream> 6 #include <sstream> 7 #include <ios> 8 #include <iomanip> 9 #include <functional> 10 #include <algorithm> 11 #include <vector> 12 #include <string> 13 #include <list> 14 #include <queue> 15 #include <deque> 16 #include <stack> 17 #include <set> 18 #include <map> 19 #include <cstdio> 20 #include <cstdlib> 21 #include <cmath> 22 #include <cstring> 23 #include <climits> 24 #include <cctype> 25 using namespace std; 26 #define XINF INT_MAX 27 #define INF 0x3FFFFFFF 28 #define MP(X,Y) make_pair(X,Y) 29 #define PB(X) push_back(X) 30 #define REP(X,N) for(int X=0;X<N;X++) 31 #define REP2(X,L,R) for(int X=L;X<=R;X++) 32 #define DEP(X,R,L) for(int X=R;X>=L;X--) 33 #define CLR(A,X) memset(A,X,sizeof(A)) 34 #define IT iterator 35 typedef long long ll; 36 typedef pair<int,int> PII; 37 typedef vector<PII> VII; 38 typedef vector<int> VI; 39 40 int main() 41 { 42 ios::sync_with_stdio(false); 43 double r,h; 44 while(cin>>r>>h){ 45 double tmp=(h+r/2); 46 int ans=(int)(tmp/r+1e-8); 47 tmp-=ans*r; 48 ans*=2; 49 tmp+=r/2; 50 if(tmp-r*(sqrt(3.0)/2)>-1e-12)ans++; 51 cout<<ans<<endl; 52 53 } 54 return 0; 55 }