zoukankan      html  css  js  c++  java
  • HDU 2289 几何+圆台

    题意;给定一个圆台杯子的R,r,H和里面水的体积V

    求h

    二分。。。。。。。。。。。。。。。。。

    因为解不出来h。。。。。。。。。。。。

    View Code
     1 /*
     2 几何
     3 圆台体积
     4 V=1/3*pi*h*(r1*r1+r2*r2+r1*r2)
     5 
     6 */
     7 #include<stdio.h>
     8 #include<string.h>
     9 #include<stdlib.h>
    10 #include<algorithm>
    11 #include<iostream>
    12 #include<queue>
    13 //#include<map>
    14 #include<math.h>
    15 using namespace std;
    16 typedef long long ll;
    17 //typedef __int64 int64;
    18 const int maxn = 105;
    19 const int inf = 0x7fffffff;
    20 const double pi=3.141592653;
    21 double r,R,H,v;
    22 
    23 double solve( double h ){
    24     double r2=h*(R-r)/H+r;
    25     return pi*h*( r2*r2+r*r+r2*r )/3.0;
    26 }
    27 const double eps = pow(10.0,-8);
    28 int main(){
    29     int ca;
    30     scanf("%d",&ca);
    31     while( ca-- ){
    32         scanf("%lf%lf%lf%lf",&r,&R,&H,&v);
    33         double lo,hi;
    34         lo=0;
    35         hi=H;
    36         double mid;
    37         while( hi-lo>eps ){
    38             mid=( lo+hi )/2.0;
    39             if( solve( mid )==v )
    40                 break;
    41             if( solve( mid )>v )
    42                 hi=mid-eps;
    43             else
    44                 lo=mid+eps;
    45         }
    46         printf("%.6lf\n",mid);
    47     }
    48     return 0;
    49 }
    keep moving...
  • 相关阅读:
    关于带权并查集
    Connections in Galaxy War ZOJ
    Supermarket POJ
    并查集判树 poj 1308
    最长异或值路径【字典树应用】
    最大异或对
    trie字典树【模板题】
    UVA536 二叉树重建 Tree Recovery
    UVA1584环状序列 Circular Sequence
    【CodeForces 622F】The Sum of the k-th Powers
  • 原文地址:https://www.cnblogs.com/xxx0624/p/2961844.html
Copyright © 2011-2022 走看看