Codeforces #199 C. Cupboard and Balloons

Source: Internet
Author: User

Reprinted Please note: http://blog.csdn.net/jiangshibiao/article/details/23164145

[Original question]

C. Cupboard and Balloonstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

A girl named Xenia has a cupboard that looks like an arc from ahead. The arc is made of a semicircle with radiusR(The cupboard's top) and two wballs of heightH(The cupboard's sides). The cupboard's depth isR, That is, it looks like a rectangle with baseRAnd heightHRegion + RegionRFrom 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 ).

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 Wils are negligibly thin.

Input

The single line contains two integersR, Bytes,H(1 digit ≤ DigitR, Bytes,HLimit ≤ limit 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

[Analysis] Because the width of the rectangle is 2 * r, it is easy to think of two rows from bottom to top.

#include<cstdio>using namespace std;int r,h,n,ans;int main(){  scanf("%d%d",&r,&h);  ans=h/r*2;  if (h%r>=double(r)/double(2)) ans+=2;else ans++;  printf("%d",ans);  return 0;}

At first, I did not think about it. I handed in the above Code directly, and the result was 17th points WA. The data is excerpted here: 3983458,776. Why is this group wrong? I found that there are only two entries at the bottom layer, so I finally output 4. But the answer is 5! Originally, ans + 1 and ans + 2 both satisfied.

That is to say, there may be a situation where you can put two more and then one more.

We can see from the slice:


We can calculate, GH = 2-sqrt (3 ). For detailed algorithms, see the code.

AC code]

#include<cstdio>#include<cmath>using namespace std;int n,ans;double r,h;int main(){  scanf("%lf%lf",&r,&h);  ans=int(h/r)*2;h-=int(h/r)*r;  if (h>=(r+0.0)/2.0) ans+=2,h-=r;  h+=r+(2.0-sqrt(3.0))*r/2.0;  if (h>=r) ans++;  printf("%d",ans);  return 0;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.