Flights (解方程)

Army is busy: military exercises had started yesterday. All types of forces are doing, hopefully, a good
job. For example, artillery is launching missiles, while aviation is delivering supplies to infantry.
The military ground space is a straight line. Aviation bases and infantry regiments are located
somewhere on the line, and artillery is launching ballistic missiles everywhere. All missile launches are
planned (don’t forget, it’s just an exercise), each at a certain time along a certain trajectory. Aviation
flights are also planned in certain time and space intervals. Everything will be fine, but there are those
missiles, which can be deadly even during exercises!
You should help aviation generals to plan the minimal safe altitude for each flight. Given the
information about flight’s time and space intervals, the minimal safe altitude for a flight is the minimal
altitude such that all missile trajectories in the corresponding time and space interval are at or below
this altitude. If there are no missiles in the flight’s time and space interval, then the minimal safe
altitude is defined to be zero.
Ballistic missiles are launched from the ground, which is defined to have a zero altitude, and fly
along a vertically symmetrical parabola. Missile speed is ignored for this problem, missiles are assumed
to follow their trajectory instantaneously.
For example, the picture below shows trajectories of two ballistic missiles in solid lines, and the
minimal safe altitudes for four different flights in dashed lines. Vertical lines delimit space intervals
of each flight in this sample. Time intervals of the flights in this sample include the launch of both
missiles.
Input
The first line of input contains a single integer n — the number of missile launches planned (1 ≤ n ≤
50000).
The following n lines describe one missile launch each. Each line contains three integers: the missile
launch point p and coordinates of the highest point of missile trajectory x and y (0 ≤ p < x ≤ 50000, 0 <
y ≤ 50); p and x are coordinates along the military ground line, y gives the altitude of the highest point
of missile trajectory. Missiles are launched one by one every minute in the order they are described in
the input.
Next line contains the single integer m — the number of flights planned (1 ≤ m ≤ 20000).
The following m lines describe one flight each. Each line contains four integers: t1 and t2 (1 ≤ t1 ≤
t2 ≤ n) — the time interval for the flight, and x1 and x2 (0 ≤ x1 ≤ x2 ≤ 50000) — the space interval
for the flight along the military ground line. Time and space intervals are inclusive of their endpoints.
Time moment 1 corresponds to the first missile launch, and time moment n corresponds to the last
one.
Output
For each flight write a separate line with the minimal safe altitude, with absolute error not exceeding
10−4
.
Sample Input
2
10 30 10
20 30 30
4
1 2 0 11
1 2 20 25
1 2 25 35
1 2 45 100
2
0 10 10
30 40 10
6
1 2 0 32
1 1 19 35
2 2 0 32
1 2 15 35
1 2 21 27
1 2 2 100
Sample Output
0.975
22.5
30.0
4.375
10.0
1.9
3.6
7.5
0.0
10.0

题目大概:

给出了n个抛物线,有m条询问,每次询问第l 到第r条抛物线,在区间x1到x2的最大值是多少(最小为0)。

思路:

直接解出这n条抛物线,然后暴力求解每次询问就可以了。

代码:


#include <bits/stdc++.h>

using namespace std;
const int maxn=5e4+10;
struct poin
{
    double a,h,k;
}p[maxn];
void make(int i,double a,double b,double c)
{
    p[i].h=b;
    p[i].k=c;
    double sum=(a-b)*(a-b);
    p[i].a=-(c/(sum));
}
double get(int i,double x)
{
    return (p[i].a*(x-p[i].h)*(x-p[i].h)+p[i].k);
}
int main()
{
    int n,m;
    while(~scanf("%d",&n))
    {
        memset(p,0,sizeof(p));
        double a,b,c;
        for(int i=1;i<=n;i++)
        {
            scanf("%lf%lf%lf",&a,&b,&c);
            make(i,a,b,c);
        }
        scanf("%d",&m);
        int l,r;
        double x1,x2;
        for(int i=1;i<=m;i++)
        {
            scanf("%d%d%lf%lf",&l,&r,&x1,&x2);
            double max_1=0;
            for(int j=l;j<=r;j++)
            {
                if(x1>=p[j].h)
                {
                    max_1=max(max_1,get(j,x1));
                }
                else if(x2<=p[j].h)
                {
                    max_1=max(max_1,get(j,x2));
                }
                else
                {
                    max_1=max(max_1,p[j].k);
                }
            }
            printf("%.5lf\n",max_1);
        }
    }
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值