三分法

https://www.luogu.org/problemnew/show/P3382

在一个先递增后递减的函数上寻找拐点

代码:

int sff(int h,int t)
{
  int h1=h1+(t-h)/3,t1=t-(t-h)/3;
  int tmp1=js(h1),tmp2=js(t2);
  if (abs(tmp1-tmp2)<eps) return(tmp1);
  if (tmp1>tmp2) return sff(h,t1);
  else return sff(h1,r);
}

 

posted @ 2018-02-20 17:16  尹吴潇  阅读(129)  评论(0编辑  收藏  举报