第五场-D-Space Golf

题面链接:点击打开链接

(一)题面:

Description

You surely have never heard of this new planet surface exploration scheme, as it is being carried out in a project with utmost secrecy. The scheme is expected to cut costs of conventional rover-type mobile explorers considerably, using projected-type equipment nicknamed "observation bullets".

Bullets do not have any active mobile abilities of their own, which is the main reason of their cost-efficiency. Each of the bullets, after being shot out on a launcher given its initial velocity, makes a parabolic trajectory until it touches down. It bounces on the surface and makes another parabolic trajectory. This will be repeated virtually infinitely.

We want each of the bullets to bounce precisely at the respective spot of interest on the planet surface, adjusting its initial velocity. A variety of sensors in the bullet can gather valuable data at this instant of bounce, and send them to the observation base. Although this may sound like a conventional target shooting practice, there are several issues that make the problem more difficult.

  • There may be some obstacles between the launcher and the target spot. The obstacles stand upright and are very thin that we can ignore their widths. Once the bullet touches any of the obstacles, we cannot be sure of its trajectory thereafter. So we have to plan launches to avoid these obstacles.
  • Launching the bullet almost vertically in a speed high enough, we can easily make it hit the target without touching any of the obstacles, but giving a high initial speed is energy-consuming. Energy is extremely precious in space exploration, and the initial speed of the bullet should be minimized. Making the bullet bounce a number of times may make the bullet reach the target with lower initial speed.
  • The bullet should bounce, however, no more than a given number of times. Although the body of the bullet is made strong enough, some of the sensors inside may not stand repetitive shocks. The allowed numbers of bounces vary on the type of the observation bullets.

You are summoned engineering assistance to this project to author a smart program that tells the minimum required initial speed of the bullet to accomplish the mission.

Figure D.1 gives a sketch of a situation, roughly corresponding to the situation of the Sample Input 4 given below.

Figure D.1. A sample situation

Figure D.1. A sample situation

You can assume the following.

  • The atmosphere of the planet is so thin that atmospheric resistance can be ignored.
  • The planet is large enough so that its surface can be approximated to be a completely flat plane.
  • The gravity acceleration can be approximated to be constant up to the highest points a bullet can reach.

These mean that the bullets fly along a perfect parabolic trajectory.

You can also assume the following.

  • The surface of the planet and the bullets are made so hard that bounces can be approximated as elastic collisions. In other words, loss of kinetic energy on bounces can be ignored. As we can also ignore the atmospheric resistance, the velocity of a bullet immediately after a bounce is equal to the velocity immediately after its launch.
  • The bullets are made compact enough to ignore their sizes.
  • The launcher is also built compact enough to ignore its height.

You, a programming genius, may not be an expert in physics. Let us review basics of rigid-body dynamics.

We will describe here the velocity of the bullet v with its horizontal and vertical components vx and vy (positive meaning upward). The initial velocity has the components vix and viy, that is, immediately after the launch of the bullet, vx = vix and vy = viy hold. We denote the horizontal distance of the bullet from the launcher as x and its altitude as y at time t.

  • The horizontal velocity component of the bullet is kept constant during its flight when atmospheric resistance is ignored. Thus the horizontal distance from the launcher is proportional to the time elapsed. 

    x=vixt(1)
  • The vertical velocity component vy is gradually decelerated by the gravity. With the gravity acceleration of g, the following differential equation holds during the flight. 

    dvydt=g(2)
    Solving this with the initial conditions of vy = viy and y = 0 when t = 0, we obtain the following. 
    y==12gt2+viyt(12gtviy)t(3)(4)
    The equation (4) tells that the bullet reaches the ground again when t = 2viy/g. Thus, the distance of the point of the bounce from the launcher is 2vixviy/g. In other words, to make the bullet fly the distance of l, the two components of the initial velocity should satisfy 2vixviy = lg.
  • Eliminating the parameter t from the simultaneous equations above, we obtain the following equation that escribes the parabolic trajectory of the bullet. 

    y=(g2v2ix)x2+(viyvix)x(5)

For ease of computation, a special unit system is used in this project, according to which the gravity acceleration g of the planet is exactly 1.0.

Input

The input consists of several tests case with the following format. 

d n bp1 h1p2 h2pn hn

For each test, the first line contains three integers, dn, and b. Here, d is the distance from the launcher to the target spot (1 ≤ d ≤ 10000), n is the number of obstacles (1 ≤ n ≤ 10), and b is the maximum number of bounces allowed, not including the bounce at the target spot (0 ≤ b ≤ 15).

Each of the following n lines has two integers. In the k-th line, pk is the position of the k-th obstacle, its distance from the launcher, and hk is its height from the ground level. You can assume that 0 < p1pk < pk + 1 for k = 1, …, n − 1, and pn < d. You can also assume that 1 ≤ hk ≤ 10000 for k = 1, …, n.

Output

Output the smallest possible initial speed vi that makes the bullet reach the target. The initial speed vi of the bullet is defined as follows. 


The output should not contain an error greater than 0.0001.

Sample Input

100 1 0
50 100

10 1 0
4 2

100 4 3
20 10
30 10
40 10
50 10

343 3 2
56 42
190 27
286 34

Sample Output

14.57738
3.16228
7.78175
11.08710


(二)题目大意:

    抽象一下:

  1. 有一条长为d的线段,你需要将一个球从线的一端丢至另外一端(恰好砸中),球在空中的运动轨迹为抛物线,当球砸到地面时没有能量损失,即反弹后会做同样的抛物线轨迹运动。
  2. 在直线上有n个障碍物,给出他们的位置和高度,球在运动时不能碰到障碍物。
  3. 给定一个d,球在运动的过程中碰撞地面的次数不能超过d次(0<=d<=15)。
  4. 求:你抛出小球时的满足条件地最小初速度。

(三)解题思路:

  1. 对于每一个确定的碰撞次数,我们可以求出每一次抛物运动的宽度,然后二分抛出小球时的角度,求满足条件的最小的角度。因为在角度和宽度一定的条件下,用一点数学知识可以求出抛物线的轨迹方程,然后判断该轨迹是否可行,并且不难得出,角度大小与可行性具有单调性。
  2. 当求出的最小的满足条件的角度小于π/4时,最优的角度是π/2,由速度的表达式及基本不等式可以推出
  3. 枚举碰撞次数,求在不同碰撞次数下的满足条件的最小初速度。更新最优解。
  4. 注意精度。

(四)具体代码

#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<vector>
#include<queue>
#include<cmath>
#include<map>
#include<algorithm>
#define esp 1e-10
#define PI acos(-1.0)/2.0
#define LL long long
#define MOD 1000000007
#define Pa pair<double,double>
#define mkp make_pair<double,double>
using namespace std;
double d,n,b,p,h;
vector<Pa>P;
bool ok(double vx,double tg,double len){                    //判断是否可行
    for(int i=0;i<P.size();i++){
        double xi=1.0*P[i].first-(int)(1.0*P[i].first/len)*len;
        double yi=tg*xi-0.5*xi*xi/(vx*vx);
        if(P[i].second-yi>esp)return false;
    }
    return true;
}
int main(){
    freopen("in.txt","r",stdin);
    while(~scanf("%lf%lf%lf",&d,&n,&b)){
        for(int i=0;i<n;i++){
            scanf("%lf%lf",&p,&h);
            P.push_back(Pa(p,h));
        }
        double ans=1e9;
        for(int i=1;i<=b+1;i++){                            //枚举碰撞次数
            double l=esp,r=PI-esp,len=d*1.0/i;
            while(abs(l-r)>esp){                            //二分抛出时小球的角度
                double mid=(l+r)/2.0;
                double vx=sqrt(len*0.5/tan(mid));           //小球的水平速度
                if(ok(vx,tan(mid),len))r=mid-esp;
                else l=mid+esp;
            }
            l=max(l,PI/2.0);r=max(r,PI/2.0);
            double v1=sqrt(len*0.5/tan(l)+len*0.5*tan(l));  //小球的合速度
            double v2=sqrt(len*0.5/tan(r)+len*0.5*tan(r));
            ans=min(ans,min(v1,v2));                        //更新最优解
        }
        printf("%.10lf\n",ans);P.clear();
    }
    return 0;
}

(五)总结:

        这个题赛场上没看,后面才发现过的人挺多的。然后补了一下,比较好想。但是开始被卡了精度(开始只算了v1),算了v2之后才过(也不知道为什么...),平时精度的问题碰到地比较少,做到了也是有收获了。,,

猜你喜欢

转载自blog.csdn.net/xbb224007/article/details/80271675
今日推荐