본문 바로가기
알고리즘/Divide and Conquer-이분탐색

crossed ladder 더블릿

by tryotto 2019. 2. 13.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <stdio.h>
#include <algorithm>
#include <cmath>
 
using namespace std;
 
double root(double m, double x) {
    return sqrt(pow(m, 2- pow(x, 2));
}
 
int main() {
    double m, n, h;
    scanf("%lf %lf %lf"&m, &n, &h);
 
    double left = 0, right = min(m, n),rst=0,mid;
    while (left < right) {        
        mid = (left + right) / 2;
        double result = h / root(m, mid) + h / root(n, mid) - 1;
        if (result <= 0) {
            if (left == mid)
                break;
            left = mid ;
 
        }
        else if (result > 0) {
            if (right == mid)
                break;            
            right = mid ;
        }
    }
    printf("%.3lf", mid);
}
cs


'알고리즘 > Divide and Conquer-이분탐색' 카테고리의 다른 글

factorial vs pow 더블릿 (PS)  (0) 2019.02.13
이진검색 더블릿 (PS)  (0) 2019.02.13
공격적인 소 더블릿 (Aggressive Cow)  (0) 2019.02.12
6236 용돈관리 (PS)  (0) 2019.02.12
2343 기타레슨 (PS)  (0) 2019.02.12