zoukankan      html  css  js  c++  java
  • 第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
    ",90-r);
    27     }
    28     return 0;
    29 }
  • 相关阅读:
    localStorage用法
    es6写法
    div滚动条
    搜索框聚焦和失焦
    初步理解前端模块化开发
    clam安装
    div行高不确定,文字和图片居中
    html页面设置<span>的高度和宽度
    一款好用的wangEditor编辑器
    3月23 防360网页的示意图
  • 原文地址:https://www.cnblogs.com/LLLAIH/p/10003808.html
Copyright © 2011-2022 走看看