简体   繁体   English

如何优化一个算法,该算法返回正整数x的值,使得部分已知函数的f(x)> = 0?

[英]How to optimize an algorithm that returns the value of a positive integer x such that f(x) >=0 for a partially known function?

The only things you know about this function are that 你对这个功能的唯一了解就是

(i) x >= 1 for f(x) such that f(x) >= 0. (i)对于f(x),x> = 1,使得f(x)> = 0。

(ii) It is strictly increasing when x > 0. (ii)当x> 0时严格增加。

(iii) Evaluating the function at any point takes constant time. (iii)在任何时候评估功能需要恒定的时间。

How do you return the value of a positive integer x such that f(x) >=0 in < O(n) time, preferably in O(log(n)) time? 如何在<O(n)时间内返回正整数x的值,使得f(x)> = 0,最好是在O(log(n))时间内?

In O(n) time, you just have to keep querying the algorithm for all positive integers until it hits f(x) >= 0. 在O(n)时间内,您只需要继续查询所有正整数的算法,直到它达到f(x)> = 0。

Evaluate f(x) for x powers of 2, until you find f(2^n) < 0 and f(2^(n+1)) >= 0. Then bisect until you find the lowest value. 评估f(x)的x次幂为2,直到找到f(2 ^ n)<0且f(2 ^(n + 1))> = 0.然后平分直到找到最低值。 It's O(log n) time to find the first power of 2 for which the function is non-negative, and then O(log n) to binary search in the range 2^n to 2^(n+1). 找到函数为非负的2的第一个幂的O(log n)时间,然后在2 ^ n到2 ^(n + 1)的范围内找到O(log n)到二进制搜索。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何优化我的函数,该函数需要一个正整数并返回下一个较小的正整数? - How to optimize my function that takes a positive integer and returns the next smaller positive integer? 用于检查非线性函数f是否总是正的算法 - An algorithm for checking if a nonlinear function f is always positive 将任何正整数转换为RGB值的算法 - Algorithm to convert any positive integer to an RGB value 找到[x / 2] yx * y不能表示的正整数? - Find positive integer that can't be expressed by [x/2] y x*y? 寻找 f(x) = a*min(b, x) 形式的函数最大值的算法? - Algorithm for finding max value of functions of the form f(x) = a*min(b, x)? 如何找到一种有效的算法来为每个x标识最小的n和k,使得f ^(n)(x)= f ^(n + k)(x) - How to find an efficient algorithm to identify for each x the smallest n and k such that f^(n)(x) = f^(n+k)(x) 查找大于或等于z(正整数,可能是2的幂)的倍数的最小整数(正整数)。 - Find smallest integer greater or equal than x (positive integer) multiple of z (positive integer, probably power of 2) 我有一个函数f(w,x,y,z)和一个目标值A,如何发现产生A的w,x,y,z的值? - I have a function f(w,x,y,z) and a target value A, how can I discover values for w,x,y,z that produce A? 算法:对整数 X 进行因式分解以获得尽可能多的不同正整数 (Y1...Yk),使得 (Y1+1)(Y2+1)...(Yk+1) = X - Algorithm: Factorize a integer X to get as many distinct positive integers(Y1...Yk) as possible so that (Y1+1)(Y2+1)...(Yk+1) = X 如果一个算法的运行时间可以表示为函数 F(x)=√n+(logn)^2 , - If an algorithm's running time can be expressed as function F(x)=√n+(logn)^2 ,
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM