zoukankan      html  css  js  c++  java
  • HDU 5954 Do Not Pour Out

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 #define rep(i,a,b) for(int i=a;i<=b;++i)
     4 #define ms(arr,a) memset(arr,a,sizeof arr)
     5 #define debug(x) cout<<"< "#x" = "<<x<<" >"<<endl
     6 double eps=1e-10;
     7 const double pi=3.1415926536;
     8 double d;
     9 double V;
    10 double longaxis,shortaxis;
    11 double calcV(double w)
    12 {
    13     if(w>-eps&&w<eps)return 0;
    14     return (w-1)*pi/w-(6*(w-1)*asin(1-w)+sqrt(2*w-w*w)*(-2*w*w+4*w-6))/3/w;
    15 }
    16 bool ok(double w)
    17 {
    18     //debug(w);
    19     //debug(calcV(w));
    20     if(calcV(w)<V+eps)return true;
    21     return false;
    22 }
    23 double solve(double l,double r)
    24 {
    25     double m;
    26     while(l<r)
    27     {
    28         m=(l+r)/2.;
    29         if(ok(m))l=m+eps;
    30         else r=m-eps;
    31     }
    32     return l;
    33 }
    34 double F(double x)
    35 {
    36     return 2*shortaxis/longaxis*(longaxis*longaxis*asin(x/longaxis)+sqrt(longaxis*longaxis-x*x)*x)/2;
    37 }
    38 int main()
    39 {
    40     //freopen("Input.txt","r",stdin);
    41     //freopen("Output.txt","w",stdout);
    42     int T;scanf("%d",&T);
    43     while(T--)
    44     {
    45         scanf("%lf",&d);
    46         if(d>=1)
    47         {
    48             printf("%.5f
    ",pi*sqrt(d*d-4*d+5));
    49             continue;
    50         }
    51         if(d==0)
    52         {
    53             printf("0.00000
    ");
    54             continue;
    55         }
    56         V=d*pi;
    57         //debug(V);
    58         double w=solve(0.,2.);
    59         //debug(w);
    60         longaxis=sqrt(w*w+4)/w;
    61         shortaxis=1;
    62         double part=sqrt(w*w+4);
    63         printf("%.5f
    ",F(longaxis)-F(longaxis-part));
    64     }
    65     //freopen("CON","w",stdout);
    66     //system("start Output.txt");
    67 }
  • 相关阅读:
    不要在init和dealloc函数中使用accessor
    Xcode6.3真机测试无法选择目标机器问题
    Objective-C基础知识
    深入理解dispatch_sync
    AFNetworking 2.0教程
    使用pngcrush压缩png图片
    自定义custom Tab Bar
    CocoaPods 安装相关问题
    iOS 编程之使用Precompile Prefix Header
    Block传值
  • 原文地址:https://www.cnblogs.com/maoruimas/p/9547092.html
Copyright © 2011-2022 走看看