其他分享
首页 > 其他分享> > 灯泡——一个数学题

灯泡——一个数学题

作者:互联网

就是相似+对勾函数

如图

 然后附上代码

#include<bits/stdc++.h>
using namespace std;
int n;
double H,h,D,a;
int main(){
	scanf("%d",&n);
	while(n--){
		scanf("%lf%lf%lf",&H,&h,&D);
		a=H-sqrt(D*H-D*h);
		if(a<0)printf("%.3f\n",D*h/H);
		else if(a>=h)printf("%.3f\n",h);
		else printf("%.3f\n",H+D-2*sqrt(D*H-D*h));
	}
}
/*
3
2 1 0.5
2 0.5 3
4 3 4
*/

 

标签:%.,一个,scanf,0.5,灯泡,int,sqrt,printf,数学题
来源: https://blog.csdn.net/m0_61523842/article/details/120458701