CSU2092: 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)(1)x=vixt

  • 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)(2)dvydt=−g


    Solving this with the initial conditions of vy = viy and y = 0 when t = 0, we obtain the following. 

    y==−12gt2+viyt−(12gt−viy)t(3)(4)(3)y=−12gt2+viyt(4)=−(12gt−viy)t


    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)(5)y=−(g2vix2)x2+(viyvix)x

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 h2⋮pn hnd n bp1 h1p2 h2⋮pn 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 < p1, pk < 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. 

 

vi=v2ix+v2iy−−−−−−−√vi=vix2+viy2


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

题意:这题呢,提干太长了,看到头皮发麻,具体意思是,有n个格挡板距离起点长度分别为p1,p2,p3...pn,然后扔球,球不停的弹啊弹弹到距离起点d的位置,但是中间不能够碰到格挡板,并且最多只能着地b次。

因为b<=15,所以可以暴力枚举着地的次数,根据着地的次数,判断每一次球运动的距离,也就是double dis = d/cnt;然后就把所有的格挡板位移到同一个抛物线内,也就是x[i] = fmod(node[i].p, dis);

有物理知道斜抛运动沿着四十五度角运动最高,那么就先判断四十五度能不能过所有的,如果能过就直接过了,不能的话就对每一个格挡板求能过的最低高度,然后看其他的能不能过。以此类推。每次取最小的,就可以了。

#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iomanip>
#define INF 0x3f3f3f3f
#define EPS 1e-7
using namespace std;

const int maxn=20;
int n, b;
double d;
struct Node
{
    double h, p;
}node[maxn];
double x[maxn];
double tempx,tempy;

double get(double x, double h, double dis)
{
    double a = h / ((x - dis) * x);
    double b = (-a) * dis;
    double k = dis / 2;
    tempy = sqrt(2*(a*k*k + b*k));
    tempx = k / tempy;
}

int check()
{
    for (int i = 0; i < n; i++){
        double h = tempy*x[i] / tempx - 0.5*x[i]*x[i] / (tempx*tempx);
        if (node[i].h-h >= EPS)
            return 0;
    }
    return 1;
}

double solve(int cnt)
{
    double dis = d/cnt;
    for (int i = 0; i < n; i++)
        //x[i] = node[i].x % dis;
        x[i] = fmod(node[i].p, dis);
    tempy = tempx = sqrt(dis/2);
    if (check())
        return tempx * sqrt(2.0);
    double tempans = INF;
    for (int i = 0; i < n; i++)
    {
        get(x[i], node[i].h, dis);
        if (check())
            tempans = min(tempans, sqrt(tempx*tempx + tempy*tempy));
    }
    return tempans;
}

int main()
{
    while(cin>>d>>n>>b)
    {
        for (int i = 0; i < n; i++)
            cin>>node[i].p>>node[i].h;
        double ans = INF;
        for (int i = 1; i <= b+1; i++)
            ans = min(ans, solve(i));
        cout<<fixed<<setprecision(7)<<ans<<endl;
    }
    return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值