思路:
- 可以知道这是一个凹型函数,但是不是严格中间小于两边
- 可以三分
- 也可以转化成二分来写
inline double f(int x) { return n/x + x - 1; }
void solve() { cin >> n >> L >> R;
int ans = f(L) < f(R)?L:R; int minn = f(sqrt(n) + 1) > f(sqrt(n))?sqrt(n):sqrt(n) + 1; if(minn >= L && minn <= R && f(ans) > f(minn))ans = minn;
int lo = L,hi = ans; while(lo < hi) { int mid = lo + hi >> 1; if(f(mid) == f(ans))hi = mid; else lo = mid + 1; } cout << lo << endl; }
标签:二分,函数,minn,int,lo,mid,sqrt,答案,ans From: https://www.cnblogs.com/cfddfc/p/17062045.html