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)