⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cup.cpp

📁 第四届百度杯编程大赛final解题报告+标程
💻 CPP
字号:
/*
 * Author: ChaeYeon
 * Created Time:  2/17/2009 4:22:46 PM
 * File Name: cup.cpp
 * Description: 
 To solve this problem, you should know that the volume of one cup is pi * (r * r + R * R + r * R) * h / 3.
 If you don't know this formula, you could find by this formula: s * h / 3.
 It's the formula to calculte the volume of taper.
 The next step after you know the formula is to calculate the high of the water.
 */
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <cstdlib>
#include <algorithm>
using namespace std;
#define out(x) fprintf(stderr, "%s: %I64d\n", #x, (long long)(x))
#define SZ(v) ((int)(v).size())
const int maxint=-1u>>1;
template <class T> bool get_max(T& a, const T &b) {return b > a? a = b, 1: 0;}
template <class T> bool get_min(T& a, const T &b) {return b < a? a = b, 1: 0;}
const double pi = acos(-1.0);
double V(double r, double R, double h, double mid) {
    double rr = r + (R - r) * mid / h;
    return pi * (r * r + rr * rr + r * rr) * mid / 3;
}

double find(double r, double R, double h, double v) {
    double ans = 0, s = 0, t = h;
    while (t - s > 1e-9) {
        double mid = (s + t) / 2;
        if (V(r, R, h, mid) <= v) {
            s = mid;
            get_max(ans, mid);
        } else {
            t = mid;
        }
    }
    return ans;
}

int main() {
    int ca;
    scanf("%d", &ca);
    while (ca--) {
        double r, R, h, v;
        scanf("%lf %lf %lf %lf", &r, &R, &h, &v);
        printf("%.6lf\n", find(r, R, h, v));
    }
    return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -