Reprint Please specify source: http://www.cnblogs.com/fraud/--by fraud
C. Cupboard and Balloons
A girl named Xenia have a cupboard that looks as a arc from ahead. The arc is made of a semicircle with radius R (the cupboard ' s top) and the walls of height h (th E cupboard ' s sides). The cupboard ' s depth is R, that's, it looks like a rectangle with base R and height h + Rfrom the sides. The figure below shows what's the cupboard looks like (the front view are on the left, the side view are on the right).
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 are a sphere with radius. Help Xenia calculate the maximum number of balloons she can put in her cupboard.
You can say that a balloon are 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 of the other. It is not a allowed to squeeze the balloons or deform them on any. You can assume that the cupboard ' s walls is negligibly thin.
Input
The single line contains the integers r, H (1≤ R, H ≤107).
Output
Print a single integer-the maximum number of balloons Xenia can put in the cupboard.
Sample Test (s) input
1 1
Output
3
Input
1 2
Output
5
Input
2 1
Output
2
Considering the high space utilization from bottom to top, it is only possible to consider whether the final top can be crammed into a balloon.
1 //#####################2 //Author:fraud3 //Blog:http://www.cnblogs.com/fraud/4 //#####################5#include <iostream>6#include <sstream>7#include <ios>8#include <iomanip>9#include <functional>Ten#include <algorithm> One#include <vector> A#include <string> -#include <list> -#include <queue> the#include <deque> -#include <stack> -#include <Set> -#include <map> +#include <cstdio> -#include <cstdlib> +#include <cmath> A#include <cstring> at#include <climits> -#include <cctype> - using namespacestd; - #defineXinf Int_max - #defineINF 0X3FFFFFFF - #defineMP (x, y) make_pair (x, y) in #definePB (x) push_back (x) - #defineREP (x,n) for (int x=0; x<n; X + +) to #defineREP2 (X,L,R) for (int x=l; x<=r; X + +) + #defineDEP (x,r,l) for (int x=r; x>=l; x--) - #defineCLR (a,x) memset (a,x,sizeof (A)) the #defineIT iterator *typedefLong Longll; $typedef pair<int,int>PII;Panax Notoginsengtypedef vector<pii>VII; -typedef vector<int>VI; the + intMain () A { theIos::sync_with_stdio (false); + Doubler,h; - while(cin>>r>>h) { $ DoubleTmp= (h+r/2); $ intAns= (int) (tmp/r+1e-8); -tmp-=ans*R; -ans*=2; thetmp+=r/2; - if(Tmp-r* (sqrt (3.0)/2) >-1e- A) ans++;Wuyicout<<ans<<Endl; the - } Wu return 0; -}
code June
Codeforces 342C Cupboard and balloons (formula title)