Refract Facts (二分) (UVALive 7292) Regionals 2015--North America - South Central USA

本文介绍了一种使用二分法解决潜艇与飞机间激光通讯角度计算的问题,通过Snell定律和给定参数,精确计算激光发射角度,确保潜艇能够准确地将信息传递给飞行中的目标。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

                                                                                      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. 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
n 1
=
sin θ 2
n 2
where n 1 and n 2 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
• n 1 , the refractive index of water, 1.0 < n 1 ≤ 2.5
• n 2 , the refractive index of air, 1.0 ≤ n 2 < n 1
Input ends with a line containing 5 zeroes (0 0 0 0 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.90
1200 4000 1.5 1.01
100 10000 2.5 1.01
0 0 0
Sample Output
44.37
11.51
2.30

 思路: 这个题比赛的时候我们推公式没有推出来,是一个一元四次的方程,然后我们当时就放弃了,后来才发现这个题原来是个二分,要求的角度是在0到90度之间的,然后对0到90不断二分,我是根据mid求出来的H,然后和给定的h比较,如果H大于h,就说明mid大了,反之亦然。

#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<cstring>
#include<set>
#include<cmath>
using namespace std;
#define PI acos(-1)
typedef long long LL;
double d,h,x,n1,n2;
double cc(double l,double r)
{

    while(r-l>=0.001)
    {
        double mid=(l+r)/2.0;
        double m=d/(tan(mid*PI/180.0));
        double w=x-m;
        double ct1=90.0-mid;
        double sinct2=sin(ct1*PI/180.0)*n2/n1;
        double hct2=asin(sinct2);
        double ct2=hct2*180.0/PI;
        double hh=w/tan(ct2*PI/180.0);
        if(hh>h)
            r=mid;
        else
            l=mid;
    }
    return l;

}
int main()
{

    while(cin>>d>>h>>x>>n1>>n2)
    {
        if(d==0&&h==0&&x==0&&n1==0&&n2==0)
            break;
        double l=0.0,r=90.0;
        double ans=cc(l,r);
        printf("%.2lf\n",ans);
    }
    return 0;
}

 

内容概要:本文介绍了基于Python实现的SSA-GRU(麻雀搜索算法优化门控循环单元)时间序列预测项目。项目旨在通过结合SSA的全局搜索能力和GRU的时序信息处理能力,提升时间序列预测的精度和效率。文中详细描述了项目的背景、目标、挑战及解决方案,涵盖了从数据预处理到模型训练、优化及评估的全流程。SSA用于优化GRU的超参数,如隐藏层单元数、学习率等,以解决传统方法难以捕捉复杂非线性关系的问题。项目还提供了具体的代码示例,包括GRU模型的定义、训练和验证过程,以及SSA的种群初始化、迭代更新策略和适应度评估函数。; 适合人群:具备一定编程基础,特别是对时间序列预测和深度学习有一定了解的研究人员和技术开发者。; 使用场景及目标:①提高时间序列预测的精度和效率,适用于金融市场分析、气象预报、工业设备故障诊断等领域;②解决传统方法难以捕捉复杂非线性关系的问题;③通过自动化参数优化,减少人工干预,提升模型开发效率;④增强模型在不同数据集和未知环境中的泛化能力。; 阅读建议:由于项目涉及深度学习和智能优化算法的结合,建议读者在阅读过程中结合代码示例进行实践,理解SSA和GRU的工作原理及其在时间序列预测中的具体应用。同时,关注数据预处理、模型训练和优化的每个步骤,以确保对整个流程有全面的理解。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值