ZOJ 3203 Light Bulb (three-point + computational ry)
The first trigger. The three-point principle is quite simple.
The Code is as follows:
#include
#include
#include
#include
#include #include
#include
#include
#include
using namespace std;#define LL __int64#define pi acos(-1.0)#define root 1, n, 1#define lson l, mid, rt<<1#define rson mid+1, r, rt<<1|1//#pragma comment(linker, /STACK:1024000000)const int mod=1e9+7;const int INF=0x3f3f3f3f;const double eqs=1e-9;const int MAXN=30000+10;double dist(double H, double h, double D, double x){ return D-x+H-D*(H-h)/x;}double TS(double H, double h, double D){ double l=D-D*h/H, r=D, ll, rr, ans1, ans2; while(r-l>=eqs){ ll=(2*l+r)/3;rr=(2*r+l)/3; ans1=dist(H,h,D,ll); ans2=dist(H,h,D,rr); if(ans1>ans2) r=rr; else l=ll; } return dist(H,h,D,l);}int main(){ int T; double H, h, d; scanf(%d,&T); while(T--){ scanf(%lf%lf%lf,&H,&h,&d); printf(%.3f,TS(H,h,d)); } return 0;}