链接:https://ac.nowcoder.com/acm/contest/894/A
来源:牛客网

华华教奕奕写几何
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 524288K,其他语言1048576K
64bit IO Format: %lld
题目描述
奕奕的几何很差,然而奕奕并不承认,所以华华扔给奕奕一道题目。如图:

已知大半圆的半径等于两个小半圆半径之和。若给出红色部分的面积,那么大圆的半径最小是多少呢?反正奕奕是不会的,所以现在请你回答。
输入描述:
输入一个正整数s表示红色部分的面积。
1<=s<=1e9
输出描述:
输出一个小数表示大圆的最小半径,保留三位小数
示例1
输入
复制
2
输出
复制
1.596
示例2
输入
复制
3
输出
复制
1.954

思路:

直接一个数学公式就好了,看到有题解写是二分,不理解这题二分什么?

显然我们想让大圆的半径最小,就要让红色部分在半圆中尽可能的多,又因为两个小半圆直径都是大半圆的半径时,红色面积最多。

然后 r * r = 4 * s / π

细节见代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#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), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define pi acos(-1)
#define gg(x) getInt(&x)
#define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
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){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/

int main()
{
    //freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
    //freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);
    
    gbtb;
    double s;
    cin>>s;
    s*=4.00;
    double r=s/pi;
    cout<<fixed<<setprecision(3)<<sqrt(r)<<endl;
    
    
    
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}