Lightoj 1062 crossed ladders (two points)

Source: Internet
Author: User
Tags acos



Title Link: http://www.lightoj.com/volume_showproblem.php?problem=1062



Test instructions: Two sticks obliquely on the wall, giving you the length of the stick and the height of their intersection distance from the ground
, find the distance between the two walls
Idea: Direct enumeration distance of two points can be
AC Code:


 
 
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stack>
#include<set>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#define MAXN 1010000
#define LL long long
#define ll __int64
#define INF 0xfffffff
#define mem(x) memset(x,0,sizeof(x))
#define PI acos(-1)
#define eps 1e-8
using namespace std;
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;}
double dpow(double a,ll b){double ans=1.0;while(b){if(b%2)ans=ans*a;a=a*a;b/=2;}return ans;}
//head
int main()
{
    int t,cas=0;
    scanf("%d",&t);
    while(t--)
    {
        double x,y,L;
        scanf("%lf%lf%lf",&x,&y,&L);
        if(L==0.0)
        {
            printf("Case %d: %.7lf\n",++cas,max(x,y));
            continue;
        }
        double l=0.0,r=max(x,y),mid;
        //cout<<l<<" "<<r<<endl;
        while(l<r)
        {
            mid=(l+r)/2.0;
            double j1=acos(mid/x),j2=acos(mid/y);
            double h=(mid*tan(j1)*tan(j2))/(tan(j1)+tan(j2));
            //cout<<h<<" "<<mid<<endl;
            if(fabs(h-L)<eps)
                break;
            if(h>L)
                l=mid;
            else
                r=mid;
        }
        printf("Case %d: %.7lf\n",++cas,mid);
    }
    return 0;
}


Lightoj 1062 crossed ladders (two minutes)


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.