Problem: Example

Input

100 1 0
50 100


Output

14.57738

Solution (in CPP):

Solution:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
using namespace std;
const int maxn=20;
const double eps=1e-9;
const double INF=1e265;
const double pi=acos(-1);
double p[maxn],h[maxn];
int n;
int sgn(double v)
{
	if(abs(v)<eps)return 0;
	else return v<0?-1:1;
}
void cal(double x1,double x2,double h2,double x3,double &a,double &b)
{
	x2-=x1;
	x3-=x1;
	a=h2/x2/(x2-x3);
	b=-a*x3;
}
bool check(int b,double d,double &tmpv)
{
	double A,B,maxA,angle,maxangle=-2*pi;
	double xl,xr;
	int k,j=0;
	tmpv=INF;
	xl=0,xr=d/(b+1);
	for(k=0;k<=b;k++)
	{
		//cout <<xl<<" "<<xr<<" "<<p[j]<<endl;
		for(;p[j]<xr+eps&&j<n;j++)
		{
			if(sgn(xl-p[j])==0||sgn(xr-p[j])==0)return false;
			cal(xl,p[j],h[j],xr,A,B);	
			//cout <<A<<" "<<B<<endl;
			angle=atan(B);
			//cout <<angle<<" "<<pi/4<<endl;
			if(sgn(maxangle-angle)<=0)
			{
				maxangle=angle;
				maxA=A;
			}
		}
		xl=xr;
		xr+=d/(b+1);
	}
	if(maxangle<pi/4)tmpv=sqrt(d/(b+1));
	else tmpv=sqrt(-1.0/(2*cos(maxangle)*cos(maxangle)*maxA));
	//cout <<b<<" "<<maxangle<<" "<<pi/4<<" "<<d<<" "<<tmpv<<endl;
	return true;
}
int main()
{
	int b,i;	
	double d,angle,v;
	double ansv=INF,tmpv;
	scanf("%lf %d %d",&d,&n,&b);
	for(i=0;i<n;i++)
		scanf("%lf %lf",&p[i],&h[i]);
	for(i=0;i<=b;i++)
		if(check(i,d,tmpv))ansv=min(ansv,tmpv);
	printf("%.6f\n",ansv);
	return 0;
}