zoukankan      html  css  js  c++  java
  • Crossed ladders---poj2507(二分+简单几何)

    题目链接:http://poj.org/problem?id=2507

     

    题意就是给你x y c求出?的距离;

    h1 = sqrt(x*x-d*d);

    h2 = sqrt(y*y-d*d);

    (h1-c)/h1 = d1/d = c/h2

    c = (h1*h2)/(h1+h2);

    二分找到d即可;

    #include<iostream>
    #include<stdio.h>
    #include<algorithm>
    #include<math.h>
    #include<string.h>
    #include<string>
    #include<stack>
    #include<vector>
    #include<map>
    using namespace std;
    #define N 2510
    #define INF 0x3f3f3f3f
    #define met(a, b) memset(a, b, sizeof(a))
    typedef long long LL;
    
    int main()
    {
        double x, y, c;
    
        while(scanf("%lf %lf %lf", &x, &y, &c)!=EOF)
        {
            double L = 0, R = min(x, y);
            while(L <= R)
            {
                double Mid = (L+R)/2;
                double h1 = sqrt(x*x-Mid*Mid);
                double h2 = sqrt(y*y-Mid*Mid);
                double temp = h1*h2/(h1+h2);
                if(fabs(temp - c)<1e-5)
                {
                    printf("%.3f
    ", Mid);
                    break;
                }
                else if(temp > c)
                    L = Mid;
                else
                    R = Mid;
            }
        }
        return 0;
    }

     

  • 相关阅读:
    pagefile.sys
    Oracle数据库同义词
    oracle临时表
    修改Oracle并行度
    Oracle 反键索引/反向索引
    Ajax基础2
    DOM高级
    面向对象--高级
    面向对象---中级
    面向对象-初级
  • 原文地址:https://www.cnblogs.com/zhengguiping--9876/p/5545742.html
Copyright © 2011-2022 走看看