ZOJ Light Bulb - 3203

题意:人左右走动,求影子L的最长长度。

思路:三分人在D上的位置。注意影子长=D-x+H-(H-h)*D/x。

 1 #include<iostream>
 2 #include<stdio.h>
 3 #include<stdlib.h>
 4 #include<memory.h>
 5 #include<string.h>
 6 #include<algorithm>
 7 #include<cmath>
 8 #define clc(a,b) memset(a,b,sizeof(a))
 9 typedef long double ld;
10 typedef long long ll;
11 const int N = 30;
12 const double eps=1e-9;
13 const int inf=-100000;
14 const int maxn=1e5+10;
15 const double Pi=acos(-1);
16 using namespace std;
17 
18 double H,h,D;
19 
20 double calc(double x)
21 {
22     return D-x+H-(H-h)*D/x;
23 }
24 
25 double solve(double l,double r)
26 {
27     //cout<<"11"<<endl;
28     double mid,midmid;
29     double d1,d2;
30     while(r-l>=eps)
31     {
32         mid=(l+r)/2;
33         midmid=(mid+r)/2;
34         d1=calc(mid);
35         d2=calc(midmid);
36         if(d1>=d2)
37             r=midmid;
38         else
39             l=mid;
40     }
41     return d1;
42 }
43 
44 int main()
45 {
46     int t;
47     scanf("%d",&t);
48     while(t--)
49     {
50         scanf("%lf%lf%lf",&H,&h,&D);
51         printf("%.3lf\n",solve((H-h)*D/H,D));
52     }
53     return 0;
54 }
View Code

 

posted @ 2015-12-18 20:52  yyblues  阅读(232)  评论(0编辑  收藏  举报