Input
The first line of the input contains an integer T (T <= 100), indicating the number of cases.
Each test case contains three real numbers H, h and D in one line. H is the height of the light bulb while h is the height of mildleZ http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vcGFyZC4gPGVtPkQ8L2VtPiBpcyBkaXN0YW5jZSBiZXR3ZWVuIHRoZSBsaWdodCBidWxiIGFuZCB0aGUgd2FsbC4gQWxsIG51bWJlcnMgYXJlIGluIHJhbmdlIGZyb20gMTA8c3VwPi0yPC9zdXA+IHRvIDEwPHN1cD4zPC9zdXA+LCBib3RoIGluY2x1c2l2ZSwgYW5kCjxlbT5IPC9lbT4gLSA8ZW0+aDwvZW0+ID49IDEwPHN1cD4tMjwvc3VwPi4gPC9wPgo8cD48c3Ryb25nPk91dHB1dDwvc3Ryb25nPjwvcD4KPHA+Rm9yIGVhY2ggdGVzdCBjYXNlLCBvdXRwdXQgdGhlIG1heGltdW0gbGVuZ3RoIG9mIG1pbGRsZW9wYXJk"s shadow in one line, accurate up to three decimal places..
Sample Input
3 2 1 0.5 2 0.5 3 4 3 4
Sample Output
1.000 0.750 4.000
我感觉这就是一道数学题:
#include
int main()
{
int n;
double H,D,h,s1,s2,x1,x2,i,s;
scanf("%d",&n);
while(n--)
{
scanf("%lf%lf%lf",&H,&h,&D);
s1=D*h/H;
x1=D*(H-h)/H;
x2=sqrt(D*(H-h));
s2=(-x2*x2+x2*(D+H)+D*(h-H))/x2;
if(x2<=x1)
s=s1;
if(x2>=D)
{
if(s1>=h)
s=s1;
else
s=h;
}
if(x2
{
if(s1>=s2)
s=s1;
else
s=s2;
}
printf("%.3f\n",s);
}
return 0;
}