这道题
说明
照到标程打
坑爹只是小事
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <ctime>
#include <cmath>
#define mxn 1000+10
#define loc
#define mx 1e20
#define df 1e-10
using namespace std;
int n;
double A;
double h[mxn];
bool ck(double x)
{
memset(h,0,sizeof(h));
h[1]=A,h[2]=x;
for (int i=2;i<=n;++i)
{
h[i+1]=2*h[i]+2-h[i-1];
if (h[i]<0) return false;
}
return true;
}
void bs()
{
double l=0,r=A,m,min=mx;
while (l+df<r)
{
m=(l+r)/2;
if (!ck(m)) l=m;
else
{
r=m;
if (h[n]<min) min=h[n];
}
}
printf("%.2lf",min);
}
int main()
{
freopen("garland.in","r",stdin);
freopen("garland.out","w",stdout);
scanf("%d%lf",&n,&A);
bs();
return 0;
}