CodeFroces342 C. Cupboard and Balloons

来源:互联网 发布:virtualbox安装ubuntu 编辑:程序博客网 时间:2024/06/05 14:52
 Cupboard and Balloons
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
Submit Status Practice CodeForces 342C

 

Description

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 + r from 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 walls are negligibly thin.

Input

The single line contains two integers r, h (1 ≤ r, h ≤ 107).

Output

Print a single integer — the maximum number of balloons Xenia can put in the cupboard.

Sample Input

Input
1 1
Output
3
Input
1 2
Output
5
Input
2 1
Output
2

 

题目大意,给定一个衣柜如图所示,给出柜子的长宽高,然后有一堆气球,圆形,半径恰好位r/2,问这个柜子最多能放多少个气球,要求这些气球全都不能变形。

其实已经想懂了,下面的分析太复杂了,好烦,所以我决定写我现在的想法,那就是,你只要从下面向上面塞气球,塞到最后判断一下是否可以再塞一个气球,就可以得出最大的塞气球数目了。阔然开朗。但是感觉当时竟然会没有想到这样的思路,到底是为什么呢。。。真的好蠢啊!!!

 

 

 

 

题目其实很好读,样例也很好过,但是我写了好久好久都没写出来的说啊!!!!因为我有一种情况没有考虑到。

 

 

这就是以r/2分得两种情况,说白了就是右边的要特判。左边我想少了一种。那就是其实最左边那种,如果有10,19这个数据,应该得到的是5,之前我得到的只能是4和3,所以是错的,因为你可以把第一第二种情况结合起来的,也就是下面放了四个球,其实上面还可以再塞一个球!像第二种情况一样,不过是超过了上面半圆那条线的。我这种一开始想的还是太僵化了!说白了就是没有把两个圆靠在一起的时候中间的空隙给利用到。

我按照这种思路直接暴力得到三种情况,取最大值就好了。想了两个小时,不想再分析了。。。。

代码如下:

#include<stdio.h>#include<math.h>#define max(a,b) a>b?a:bint main(){int r, h, ans1, ans2, ans3;scanf("%d%d", &r, &h);if(2 * h >= r){ans1 = 2 + 2 * ( (h - ((r + 1) / 2) ) / r);ans2 = 1 + 2 * (h / r);ans3 = 3 + 2 * ((r + h) - (sqrt(3) / 2 + 1) * r) / r;ans1 = max(ans1, ans2);ans1 = max(ans1, ans3);printf("%d\n", ans1);}elseprintf("1\n");return 0; } 


 

 

0 0
原创粉丝点击