Refract Facts(UVALive 7292)

Description

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.
在这里插入图片描述
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
s i n θ 1 s i n θ 2 = n 1 n 2 \frac{sinθ1}{sinθ2}=\frac{n1}{n2} sinθ2sinθ1=n2n1
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.)
在这里插入图片描述

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, 1 ≤ d ≤ 800
• h, the height of the plane in feet, 100 ≤ h ≤ 10, 000
• x, the horizontal distance from the sub to the plane in feet, 0 ≤ x ≤ 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 0 0 0 0).
ACM-ICPC Live Archive: 7292 – Refract Facts 2/2

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

题解:

二分角度,注意弧度与角度的转换,补充一下asin(),asin( 1 2 1\over 2 21)=30.
注意θ1和θ2的位置(因为这个错了一次 ,还有不能用平方和开根的方法求解,会T,不要问为什么
在这里插入图片描述

代码如下:
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<map>
#include<set>
#define max(a,b)   (a>b?a:b)
#define min(a,b)   (a<b?a:b)
#define swap(a,b)  (a=a+b,b=a-b,a=a-b)
#define maxn 27
#define N 100000000
#define INF 0x3f3f3f3f
#define mod 1001113
#define e  2.718281828459045
#define eps 1.0e-5
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define read(x) scanf("%d",&x)
#define put(x) prllf("%d\n",x)
#define memset(x,y) memset(x,y,sizeof(x))
#define Debug(x) cout<<x<<" "<<endl
#define lson i << 1,l,m
#define rson i << 1 | 1,m + 1,r
#define ll long long
//std::ios::sync_with_stdio(false);
//cin.tie(NULL);
//const int maxn=;
using namespace std;


double d,x,h,n1,n2;
int main()
{
    while(cin>>d>>h>>x>>n1>>n2)
    {
        if(d==0&&h==0&&x==0&&n1==0&&n2==0)
            break;
        double mid,s,k,l=0,r=90;
        while(r-l>=eps)
        {
            mid=(l+r)/2;
            s=mid*PI/180;
            k=asin(sin(s)*n2/n1);
            if(x>=d*tan(s)+h*tan(k))
                l=mid;
            else
                r=mid;
        }
        printf("%.2lf\n",90-l);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值