题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1062
题意:两根棍子斜放在墙上,给你棍子的长度和他们交点距离地面的高度
,求两个墙之间的距离
思路:直接枚举距离二分即可
ac代码:
#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;
}
时间: 2024-10-09 20:39:18