Cattle-off practice match 46 A Chihuahua teach Olympus write geometry (simple math)

Links: https://ac.nowcoder.com/acm/contest/894/A
Source: Cattle-off network

Chihuahua teach Olympus write geometric
time limit: C / C ++ 1 second, other languages 2 seconds
to space constraints: C / C ++ 524288K, other languages 1048576K
64bit IO the Format:% LLD
Title Description
Olympus geometry is poor, but Olympus does not recognize, so China and China Olympus throw a topic. Figure:

Known radius equal to a large semicircle and two small semicircular radii. If given the red part of the area, the minimum radius of the great circle is how much? Anyway, it is not as lively as ever, so now please answer.
Input Description:
enter a positive integer s represented by the area of the red part.
1 <= s <= 1e9
output Description:
outputting a fractional radius of the great circle represents a minimum, three decimal places
Example 1
Input
Copy
2
output
copy
1.596
Example 2
Input
Copy
3
output
copy
1.954

Ideas:

Direct a mathematical formula like to see there is a solution to a problem write-half, did not understand half of what this problem?

Obviously we want the minimum radius of the great circle, we should let the red part as much as possible in a semicircle, and because the two small semi-circle diameter radius are big semicircle, most red area.

Then r * r = 4 * s / π

See details Code:

#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';
        }
    }
}



Guess you like

Origin www.cnblogs.com/qieqiemin/p/11300756.html