csuoj-1712-Refract Facts

来源:互联网 发布:云计算股票龙头股 编辑:程序博客网 时间:2024/06/05 08:34

Description

Input

Output

Sample Input

600 600 1000 1.333 1.01600 1200 4000 1.5 1.01400 100 10000 2.5 1.010 0 0 0 0

Sample Output

44.3711.512.30


就是一个飞机给一个潜水艇发信号,然后潜水艇要给飞机发信号。然后告诉一x代表他们的距离,n1,n2分别代表水的折射率和空气的折射率,d是潜水艇深度,h是飞机高度,然后让你求潜水艇的仰角(仰角俯角分不清)


这题真是想了好久啊,乱推公式,发现一个高次的,果断gg,最后还是在队友的提醒下发现可以枚举角度什么的,然后就顺利ac了~~~

#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<iostream>using namespace std; #define PI 3.14159265358 int main(){    double d, h, x,n1, n2;    while (scanf("%lf%lf%lf%lf%lf",&d,&h,&x,&n1,&n2))    {        if (d==0&&h==0&&x==0&&n1==0&&n2==0)            break;        double ans = 90;        double s = 0.0;        double j;        if (x == 0)        {            printf("90.00\n");            continue;        }        for(j=0.001;j<90;j+=0.001)        {            double xxx = j * PI / 180.0;            double y = d / tan(xxx);            if (x < y)            continue;            double yy = y * y;            double xx = yy * (h * h + ((x - y) * (x - y)));            double yyy = (yy + d * d) * (x - y) * (x - y);            double fff = (n1 * n1) / (n2 * n2) - xx/yyy;             if (fabs(fff-0.0)  < ans)            {                ans = fabs(fff-0.0);                s = j;                //printf("%lf\n",s);            }        }        printf("%.2lf\n",s);    }}


0 0