Topic Connection: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3366
Title: Test Instructions:
, people move around, seeking the longest length of the shadow L. According to the figure, it is easy to find that when the lamp, the person's head and corner into a straight line (assuming at this time the person standing at a point), the length of this time is the shadow all on the ground the longest length. When people go to the right, the shadow begins to be projected onto the wall, and when the person is affixed to the wall, the shadow length is the height of the human being. So when people walk from point A (set) to the wall.
Problem Solving Ideas:
Depending on the test instructions, you can find the function: L = d-x + h-d * (h-h)/x;
The function is incremented and then decremented, which is a convex function, so we can solve it by three-point method.
#include <iostream>#include <cstdio>using namespace STD;Const Doubleeps=1e-10;DoubleH,h,d;DoubleCalDoublex) {returnD-x + h-d * (h-h)/x;//Similar}DoubleGetDoubleLDoubleR//Three min{DoubleMID,MIDMID,D1,D2; while(r-l>=eps) {mid= (l+r)/2; Midmid= (MID+R)/2;if(Cal (Mid) >=cal (midmid)) R=midmid;ElseL=mid; }returnCal (mid);}intMain () {DoubleL,r;intTCin>>t; while(t--) {Cin>>H>>h>>D; L= (h-h) *d/h;the boundaries of//xR=d;printf("%.3lf\n", Get (L, R)); }return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Zoj 3203 Light Bulb