程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> HDU 影子問題

HDU 影子問題

編輯:C++入門知識

Problem Description Compared to wildleopard's wealthiness, his brother mildleopard is rather poor. His house is narrow and he has only one light bulb in his house. Every night, he is wandering in his incommodious house, thinking of how to earn more money. One day, he found that the length of his shadow was changing from time to time while walking between the light bulb and the wall of his house. A sudden thought ran through his mind and he wanted to know the maximum length of his shadow.

\

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.Bkjia.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

#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(x2x1)
{
if(s1>=s2)
s=s1;
else
s=s2;
}


printf("%.3f\n",s);
}
return 0;
}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved