问题标签 [upperbound]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
141 浏览

algorithm - 如果算法的上限和下限相同,会发生什么?

正是问题所问的。这是我明天的期中考试问题,我似乎无法在网上或我的教科书中找到答案。谢谢您的帮助!!

0 投票
2 回答
1361 浏览

c++ - C++ 中的上界/下界函数

我正在尝试使用这些函数找到我的向量(可能的向量)的上限和下限。结构数据包含 3 个字符串,我使用字符串日期进行比较。

但是这样做,编译器会显示以下消息:

使用这些功能的正确方法是什么?

0 投票
10 回答
19343 浏览

c++ - rationale for std::lower_bound and std::upper_bound?

STL provides binary search functions std::lower_bound and std::upper_bound, but I tend not to use them because I've been unable to remember what they do, because their contracts seem completely mystifying to me.

Just from looking at the names, I'd guess that "lower_bound" might be short for "last lower bound",
i.e. the last element in the sorted list that is <= the given val (if any).
And similarly I'd guess "upper_bound" might be short for "first upper bound",
i.e. the first element in the sorted list that is >= the given val (if any).

But the documentation says they do something rather different from that-- something that seems to be a mixture of backwards and random, to me. To paraphrase the doc:
- lower_bound finds the first element that's >= val
- upper_bound finds the first element that's > val

So lower_bound doesn't find a lower bound at all; it finds the first upper bound!? And upper_bound finds the first strict upper bound.

Does this make any sense?? How do you remember it?

0 投票
4 回答
4395 浏览

c++ - 在数组中搜索上界

我正在尝试使用变量中的值作为上限来获取数组中最近的上限(除非找到等效值)的索引,然后在数组中的同一索引处找到值。sizesumvalue

例如:如果 in 的sum值为 270,我的程序应该找到位于索引 6 in 的值 280size并输出对应的值value[6]

0 投票
0 回答
615 浏览

statistics - kullback leibler 散度限制

对于 N 个值的分布,我如何有效地限制同一随机场上所有非负分布之间的最大分歧?例如,对于取值在 ([1,2,3,4]) 中的随机变量的所有分布,即 N = 4,并且 a = 1 或 a = 2 或 a = 3 或 a = 4 总是非零(但可以非常小,例如 1e-1000)。

是否存在已知界限(除了无穷大)?假设给定数字 N,均匀分布 [1/4 1/4 1/4 1/4] 和“delta” [1e-10 1e-10 1e-10 1/(1+3e-10) ]超过N是最大的?...

提前谢谢大家,A。

0 投票
1 回答
262 浏览

c - 二分查找与最后一次匹配最近的匹配

我正在实施有效的算法来搜索(键或最近匹配(上限))的最后一次出现。

到目前为止,我得到了这个。

让我们有一个数组{0,0,1,5,9,9,9,9},关键是6 Fce 应该返回 index 7,但我的 fce 返回4

请注意,我不想线性迭代到最后一个匹配索引。

请记住,我有解决方案,我更改参数 fce(添加开始,结束索引)并使用 fce 从找到的上限到数组末尾进行另一次二进制搜索(仅当我没有找到完全匹配时last_occur==-1)。

我想问是否有更好/更清洁的解决方案来实施它?

0 投票
2 回答
71 浏览

algorithm - pi中4位数字序列的上限

如果这不是这个问题的正确 SE 站点,请告诉我。

一位朋友分享了他通过电话收到的这个面试问题,我试图自己解决这个问题。我将解释:

给出了作为字符串的pi最多位数的值。n

如何在此字符串中找到所有重复的 4 位序列?

这部分看起来相当直截了当。将 4 个字符序列添加到哈希表中,每次递增一个字符。在插入哈希表之前检查当前的 4 个字符序列是否已经存在。如果是这样,那么您找到了重复项。将其存储在某处,然后重复该过程。有人告诉我这或多或少是正确的。

我的问题是关于第二个问题:

上限是多少?

n = 10,000,000就是一个例子。

诚然,我的算法背景非常生疏。我的第一个想法是上限一定与 n 有关,但有人告诉我不是。

我该如何计算?

编辑

我也愿意接受一个无视上限与n. 任何一个都可以接受。

0 投票
2 回答
1668 浏览

postgresql - Postgres int4range 上限意外值

使用 PostgreSQL 9.4:

让我们进一步检查:

来自 pg 文档:

上(任意范围) | range 的元素类型 | 范围上限 | 上(数字范围(1.1,2.2))| 2.2

虽然3从技术上讲是整数范围的上限[1,3) ∩ ℕ = {1, 2},但所有自然数 ≥ 2 也是如此。我希望该upper函数返回范围的上界(最小上限)。

我错过了什么吗?

0 投票
2 回答
485 浏览

scala - Scala中Upperbound和Lowerbound的理解

我有这个scala代码:

我们可以看到Creature、Person和Employee之间的层级关系:

在 def 主目录中:

我能理解的是:

  1. A <: B定义 A 必须是子类型或等于 B(上限)

  2. A >: B定义 A 必须是超类型或等于 B(下限)

但是#4 发生了什么?为什么没有错误?由于 Employee 不是 Person 的超类型,我希望它不应该符合绑定类型参数[U >: T]

谁能解释一下?

0 投票
3 回答
23630 浏览

c++ - 上限和下限的基本二进制搜索之间的区别?

在文章http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=binarySearch中,作者讨论了二分搜索。他区分了找到某事为真的最低值和某事为假的最高值。正在搜索的数组看起来像:

假 假 假 真 真

我很好奇为什么这两种情况不同。为什么你不能只找到正确的最小值,然后减去一个以找到错误的最大值?

Edit2:好的,所以我理解下限和上限。现在,我很难理解,在搜索大于或等于查询的最小整数时,为什么我们不能只更改if(mid>query)toif(mid>=query)并让它做下限而不是上限。

编辑:这是文章所说的:

“现在我们终于得到了实现二进制搜索的代码,如本节和上一节所述:

...

如果我们想找到 p(x) 为假的最后一个 x,我们会设计(使用与上述类似的原理)类似的东西:

。”