每日一题 day50 打卡
Analysis
用初中学的相似推一波式子,再用三分一搞就好了。
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #define int long long 6 #define rep(i,s,e) for(register int i=s;i<=e;++i) 7 #define dwn(i,s,e) for(register int i=s;i>=e;--i) 8 using namespace std; 9 inline int read() 10 { 11 int x=0,f=1; 12 char c=getchar(); 13 while(c<'0'||c>'9') {if(c=='-') f=-1; c=getchar();} 14 while(c>='0'&&c<='9') {x=x*10+c-'0'; c=getchar();} 15 return f*x; 16 } 17 inline void write(int x) 18 { 19 if(x<0) {putchar('-'); x=-x;} 20 if(x>9) write(x/10); 21 write(x%10+'0'); 22 } 23 int T; 24 double H,h,D; 25 double L1,L2; 26 double calc(double x) 27 { 28 double dis=(double)(H*x)/(double)(H-h); 29 // cout<<"dis:"<<dis<<" "<<"fz:"<<(double)(H*x)<<" "<<"fm:"<<(double)(H-h)<<" x:"<<x<<endl; 30 if(dis<=D) return dis-x; 31 else 32 { 33 L1=(double)(D-x); 34 L2=((double)(D*h)-(double)(L1*H))/(double)(D-L1); 35 return L1+L2; 36 } 37 } 38 signed main() 39 { 40 T=read(); 41 while(T--) 42 { 43 scanf("%lf%lf%lf",&H,&h,&D); 44 double l=0.0,r=D; 45 while(r-l>=1e-11) 46 { 47 double mid1=l+(r-l)/3,mid2=r-(r-l)/3; 48 // cout<<"l:"<<l<<" "<<"r:"<<r<<" "<<"mid1:"<<mid1<<" "<<"mid2:"<<mid2<<endl; 49 if(calc(mid1)<=calc(mid2)) l=mid1; 50 else r=mid2; 51 // system("pause"); 52 } 53 printf("%.3lf ",calc(l)); 54 } 55 return 0; 56 }
请各位大佬斧正(反正我不认识斧正是什么意思)