zoukankan      html  css  js  c++  java
  • codeforces 342C Cupboard and Balloons(公式题)

    转载请注明出处: http://www.cnblogs.com/fraud/           ——by fraud

    C. Cupboard and Balloons

    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).

    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 test(s)
    input
    1 1
    output
    3
    input
    1 2
    output
    5
    input
    2 1
    output
    2

     

    考虑到从下往上开始摆的空间利用率高,于是只需要考虑最终的顶上还能否再塞进一个气球即可。

     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 }
    代码君
  • 相关阅读:
    NBIbatis 微信框架
    NBIbatis 框架体系说明
    NBIbatis 基础框架
    .NET开发者必备的工具箱
    开源中国上一些有用的开源系统
    TfS+强制删除签出锁定项
    thinkphp支持大小写url地址访问,不产生下划线
    sqlserver 链接 ODBC 访问 MySql
    ibatis + log4net 配置注意事项
    Devexpress GridView内嵌dx:ASPxGridLookup取得控件值乱跳解决方案
  • 原文地址:https://www.cnblogs.com/fraud/p/4376948.html
Copyright © 2011-2022 走看看