第12周组队赛

B.

B - Refract Facts

A submarine is using a communications laser to send a message to a jet cruising overhead. The sea surface is flat. The submarine is cruising at a depth d below the surface. The jet is at height h above the sea surface, and a horizontal distance x from the sub. The submarine turns toward the jet before starting communications, but needs to know the angle of elevation, φ, at which to aim the laser.

refract.png

When the laser passes from the sea into the air, it is refracted (its path is bent). The refraction is described by Snell's law, which says that light approaching the horizontal surface at an angle θ1, measured from the vertical, will leave at an angle θ2, given by the formula

sin θ1 / sin θ2 = n1 n2

where n1 and n2 are the respective refraction indices of the water and air. (The refraction index of a material is inversely proportional to how fast light can travel through that material.)

snell.png

Input

Each test case consists of a single line of input containing 5 space-separated floating point numbers:

  • d, the depth of the submarine (specifically, of the laser emitter) in feet, <= <= 800
  • h, the height of the plane in feet, 100 <= <= 10,000
  • x, the horizontal distance from the sub to the plane in feet, <= <= 10,000
  • n1, the refractive index of water, 1.0 n1 <= 2.5
  • n2, the refractive index of air, 1.0 <= n2 n1

Input ends with a line containing 5 zeroes (0).

Output

For each test case, print a single line containing the angle of elevation φ at which the submarine should aim its laser to illuminate the jet.

The angle should be displayed in degrees and rounded to the closest 1/100 of a degree. Exactly two digits after the decimal point should be displayed.

Sample Input

600 600 1000 1.333 1.01
600 1200 4000 1.5 1.01
400 100 10000 2.5 1.01
0 0 0 0 0

Sample Output

44.37
11.51
2.30
题意:一个潜艇想要与海面上的飞机交互信息,想要知道潜艇的仰角φ,h为飞机到海面的距离,d为潜艇到海面的距离,x为飞机与潜艇的水平距离,n1为水的折射率,n2为空气的折射率,θ1为入射角,θ2为出射角,
满足公式sinθ1/sinθ2=n1/n2,输出保留两位小数.
分析:我们只知道h,d,x为固定距离,现在假设我们的眼睛就是飞机的位置,θ1,θ2随着飞机的位置改变而改变,要想在0-90度里找到θ1,我们采用二分法,满足折射率公式即
sinθ1/sinθ2=n1/n2,且满足h*tanθ2+d*θ1=x,切记将角度化为弧度值,在double型数据进行数值比较时,应当采用精度值 #define eps 1e-6-1e-8
 1 #include<cstdio>
 2 #include<algorithm>
 3 #include<cmath>
 4 #include<iostream>
 5 using namespace std;
 6 #define PI 3.1415926
 7 #define eps 1e-6
 8 int main()
 9 {
10     double d,h,x,n1,n2;
11     while(~scanf("%lf %lf %lf %lf %lf",&d,&h,&x,&n1,&n2))
12     {
13     if(d==0&&h==0&&d==x&&h==n1&&n2==0)
14         break;
15      double l=0,r=90,ang1,ang2,mid;
16     while(l+eps<=r)
17     {
18     mid=(l+r)/2;
19     ang1=mid/180*PI;
20     ang2=asin(sin(ang1)*n2/n1);
21     if(h*tan(ang2)+d*tan(ang1)<=x)
22         l=mid;
23     else
24         r=mid;
25     }
26     printf("%.2lf\n",90-r);
27     }
28     return 0;
29 }

 

转载于:https://www.cnblogs.com/LLLAIH/p/10003808.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值