算法以根据m查找配对。

huangapple go评论58阅读模式
英文:

Algorithm to find pairs depending on m

问题

我想编写一个算法来根据 m 寻找配对数量。

m 等于数组中 a[i] 出现的次数(例如,如果数字 3 出现两次,则 m=2)。

如果 m < 2,则没有配对;如果 m = 2,则有 1 对配对;如果 m = 3,则有 3 对配对;如果 m = 4,则有 6 对配对,依此类推。

英文:

I want to write an algorithm to find the number of pairs based on m.

m is equal to the number of times a[i] appears in an array (e.g. if the number 3 appears two times then m=2).

If m<2 then there are no pairs, if m=2 then 1 pair, if m=3 then 3 pairs, if m=4 then 6 pairs, and so on.

答案1

得分: 1

问题仍然不是很清楚,但是可以从 m 个项目中构建的成对数量是 (m 选择 2) = m*(m-1)/2。

英文:

The question is still not very clear, but the number of pairs that can be built out of m items is (m choose 2) = m*(m-1)/2.

huangapple
  • 本文由 发表于 2020年10月8日 16:12:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/64258400.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定