Codeforces round199Div2 C

来源:互联网 发布:vmware 网络桥接 编辑:程序博客网 时间:2024/06/04 01:15

题解:

首先算长方体可以放下几个,然后算出剩余的高,如果h>=r/2&&h<sqrt(3.0)/2*r,那么还可以放两个气球,如果h>=sqrt(3.0)/2*r,则可以放3个气球,否则还能放一个,于是答案可得,这题主要是要考虑清楚,起先没考虑到剩余h足够是可能可以放下3个,要全面考虑

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


原创粉丝点击