高难度、高挑战的一个算法,高手请进,谢谢了!

askwho 2005-12-17 09:34:26
Consider the following problem. We have a procedure
that computes the function
int f(int x)
It is known that
a) f is increasing, so x<y implies f(x)<f(y)
b) computing f(x) takes time linear in x
We are also given a value y0, and it is required to
compute the smallest integer x0 such that
f(x0) >= y0
Describe in detail an efficient algorithm for computing x0.
In terms of x0, analyse its efficiency (in big-oh notation).
You cannot use any facts about f other than those given
above. Why is it important that f is increasing rather
than merely non-decreasing (x<=y implies f(x) <= f(y))?
...全文
282 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
fiftymetre 2005-12-17
  • 打赏
  • 举报
回复
二分查找(数据必须已排序) 快速排序 一般为这样呵呵

顶一个
askwho 2005-12-17
  • 打赏
  • 举报
回复
能详细解释一下吗,谢谢.
darkstar21cn 2005-12-17
  • 打赏
  • 举报
回复
类似二分查找的方法咯。
最主要的确定最初的区域。
goodluckyxl 2005-12-17
  • 打赏
  • 举报
回复
能详细解释一下吗,谢谢.

//你的题目意思就是f(x)是一个单调递增函数
f(x)的值随着x的递增单调递增
然后给定一个 x的定义域 和指定值y
要求找出定义域中的一个x使得f(x)>=y 最接近并且最接近y
根据题目意思 f(x)是一个单调函数 所以给出[x0,xn]区间中的[f0,fn]也是递增的
fx的查找满足二分法的条件

//analyse its efficiency
要求你分析效率 效率是 O(log2(n))

// Why is it important that f is increasing rather
than merely non-decreasing
要你分析为什么f(x)的单调增 比 单调不减更重要
减少比较次数 单调不减有特例存在

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧