cplib

This documentation is automatically generated by competitive-verifier/competitive-verifier

View the Project on GitHub NEET-6z/cplib

:warning: src/math/threeway_search.hpp

Depends on

Code

#include "../template.hpp"

template<class T,class F>
T threeway_search(T low,T high,F f,int itr){
    while(itr--){
        T l=(low*2+high)/3;
        T r=(low+high*2)/3;
        if(f(l)>f(r)) low=l;
        else high=r;
    }
    return low;
}
#line 2 "src/template.hpp"
#include <bits/stdc++.h>
using namespace std;
#define si(a) (long)a.size()
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(int)(n);++i)
template<typename S,typename F> bool chmin(S&a,F b){return b<a?(a=b,1):0;}
template<typename S,typename F> bool chmax(S&a,F b){return b>a?(a=b,1):0;}
bool _=(ios::sync_with_stdio(0),cin.tie(0),cout<<fixed<<setprecision(16),0);
#line 2 "src/math/threeway_search.hpp"

template<class T,class F>
T threeway_search(T low,T high,F f,int itr){
    while(itr--){
        T l=(low*2+high)/3;
        T r=(low+high*2)/3;
        if(f(l)>f(r)) low=l;
        else high=r;
    }
    return low;
}
Back to top page