• [HDU


    [HDU - 5954 ] Do not pour out( 几何,二分法,积分)

    HDU - 5954

    题意:

    你有一个圆柱杯。底部直径为2个单位,高度为2个单位。
    杯中的液位高度为d(0≤d≤2)。当您将杯子倾斜到最大角度以致没有倒出内部液体时,液体表面的面积是多少?

    思路:

    代码:

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <bits/stdc++.h>
    #define ALL(x) (x).begin(), (x).end()
    #define sz(a) int(a.size())
    #define rep(i,x,n) for(int i=x;i<n;i++)
    #define repd(i,x,n) for(int i=x;i<=n;i++)
    #define pii pair<int,int>
    #define pll pair<long long ,long long>
    #define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
    #define MS0(X) memset((X), 0, sizeof((X)))
    #define MSC0(X) memset((X), '', sizeof((X)))
    #define pb push_back
    #define mp make_pair
    #define fi first
    #define se second
    #define eps 1e-10
    #define chu(x)  if(DEBUG_Switch) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
    #define du3(a,b,c) scanf("%d %d %d",&(a),&(b),&(c))
    #define du2(a,b) scanf("%d %d",&(a),&(b))
    #define du1(a) scanf("%d",&(a));
    using namespace std;
    typedef long long ll;
    ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
    ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
    ll powmod(ll a, ll b, ll MOD) { if (a == 0ll) {return 0ll;} a %= MOD; ll ans = 1; while (b) {if (b & 1) {ans = ans * a % MOD;} a = a * a % MOD; b >>= 1;} return ans;}
    ll poww(ll a, ll b) { if (a == 0ll) {return 0ll;} ll ans = 1; while (b) {if (b & 1) {ans = ans * a ;} a = a * a ; b >>= 1;} return ans;}
    void Pv(const vector<int> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%d", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("
    ");}}}
    void Pvl(const vector<ll> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%lld", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("
    ");}}}
    inline long long readll() {long long tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') { fh = -1; } c = getchar();} while (c >= '0' && c <= '9') { tmp = tmp * 10 + c - 48, c = getchar(); } return tmp * fh;}
    inline int readint() {int tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') { fh = -1; } c = getchar();} while (c >= '0' && c <= '9') { tmp = tmp * 10 + c - 48, c = getchar(); } return tmp * fh;}
    void pvarr_int(int *arr, int n, int strat = 1) {if (strat == 0) {n--;} repd(i, strat, n) {printf("%d%c", arr[i], i == n ? '
    ' : ' ');}}
    void pvarr_LL(ll *arr, int n, int strat = 1) {if (strat == 0) {n--;} repd(i, strat, n) {printf("%lld%c", arr[i], i == n ? '
    ' : ' ');}}
    const int maxn = 1000010;
    const int inf = 0x3f3f3f3f;
    /*** TEMPLATE CODE * * STARTS HERE ***/
    #define DEBUG_Switch 0
    double d;
    const double pi = acos(-1);
    int sgn(double x)
    {
        if (fabs(x) < eps) {
            return 0;
        } else if (x > 0) {
            return 1;
        } else {
            return -1;
        }
    }
    double get_V(double mid)
    {
        double a0 = acos(1 - 2 * tan(mid));
        double res = (sin(a0) - a0 * cos(a0)) - 1.0 / 3.0 * pow(sin(a0), 3);
        res /= tan(mid);
        return res;
    }
    int main()
    {
        int t;
        t = readint();
        while (t--) {
            cin >> d;
            if (sgn(d) == 0) {
                printf("0.00000
    ");
            } else if (sgn(d - 1) >= 0) {
                double ans = pi * sqrt(d * d - d * 4 + 5);
                printf("%.5f
    ", ans );
            } else {
                double l = 0;
                double r = pi / 4;
                repd(rp, 1, 800) {
                    double mid = (l + r) * 0.5;
                    double res = get_V(mid);
                    if (sgn(res - d * pi) > 0) {
                        r = mid;
                    } else {
                        l = mid;
                    }
                }
                double theta = l;
                double a = acos(1 - 2 * tan(theta));
                double S = a - sin(a) * cos(a);
                double ans = S / sin(theta);
                printf("%.5f
    ", ans );
            }
        }
    
        return 0;
    }
    
    
    
  • 相关阅读:
    字符串转list
    vant下拉单选
    断点续传(上传)C#版
    7z压缩测试
    SQL SERVER查看表字段信息
    FTP安全组设置
    Unable to find @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest
    Charles 抓包使用教程
    董明珠语录
    京东 Vue3 组件库 nutui 3.0 发布,支持小程序开发
  • 原文地址:https://www.cnblogs.com/qieqiemin/p/13903964.html
Copyright © 2020-2023  润新知