注意第7行即可
void solve(double l,double r) { //l左边界,r右边界 double eps = 1e-12;//精度 while (r - l > eps) { double mid = (l + r) / 2.0; double mmid = (mid + r) / 2.0; if (f(mid) < f(mmid))//计算最小值用<,若为最大值则> r = mmid; else l = mid; } cout<<r; }
注意第7行即可
void solve(double l,double r) { //l左边界,r右边界 double eps = 1e-12;//精度 while (r - l > eps) { double mid = (l + r) / 2.0; double mmid = (mid + r) / 2.0; if (f(mid) < f(mmid))//计算最小值用<,若为最大值则> r = mmid; else l = mid; } cout<<r; }