zoj 3203 Light Bulb(三分)

来源:互联网 发布:深入java虚拟机 pdf 编辑:程序博客网 时间:2024/05/16 15:32

知道H,h和D,H:灯的高度,h是人的高度,D是灯和墙的距离,求人的阴影L的最大长度

这种数学题最恶心了,一开始搞错了D,所以公式推出来错的一塌糊涂..还好mjy助我.



可求:L=(h-H)*D/(D-x)+H+x


有了公式就很水了...三分。

/*Problem ID:meaning:Analyzing:*/#include <iostream>#include<cstdio>#include<cmath>#include<cstdlib>#include<cstring>#include<vector>using namespace std;typedef struct even{int y1,y2,x;}even;#define FOR(i,s,t) for(int i=(s); i<(t); i++)#define LL long long#define BUG puts("here!!!")#define print(x) printf("%d\n",x)#define STOP system("pause")#define eps 1e-8#define PI acos(-1.0)#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define maxn 16666LL gcd(LL a,LL b) {return a?gcd(b%a,a):b;}double D,H,h;double f(double x){    return (h-H)*D/(D-x)+H+x;}int main(){    int T;    cin>>T;    while(T--){        scanf("%lf%lf%lf",&H,&h,&D);        double L=0,R=h*D/H;        double mid,midmid;        while(R-L>eps){            mid=(L+R)/2;            midmid=(R+mid)/2;            if(f(mid)>f(midmid))                R=midmid;            else                L=mid;        }        printf("%.3lf\n",f(L));    }   return 0;}


原创粉丝点击