-1

我正在尝试执行以下操作:

给定几个日期,比如 A、B 和 C,我想

  1. 将 (C - A) 划分为 N 个区间
  2. 其中一个区间必须以 B 作为其界限
  3. 间隔应尽可能接近相等

任何人都可以提出一种有效的算法来实现这一目标吗?谢谢!

4

1 回答 1

0

举个例子:

A = 0
B = 45
C = 100
N = 10 interval  (10 interval = 11 bound)

1:找到最接近比率 AB / AC 的比率 X/N

4/10 < 45/100 5/10
we will take X = 4 in this example (the result will vary depending on how you round it.

2:将先前计算的绑定数设置为从A绑定到B

A to B:
  Interval number 4 (from previous value)
  Bound number 5
  Average interval length is (45-0) / 4 = 11
Bound 0 = 0
Bound 1 = 11
Bound 2 = 22
Bound 3 = 33 
Bound 4 = 45

3:设置取自先前计算的绑定数,使其绑定从 B 到 C

B to C:
  Interval number 6 (the rest)
  Bound number 7
  Average interval length is (100 - 45) / 6 = 9
Bound 4 = 45
Bound 5 = 54
Bound 6 = 63
Bound 7 = 72
Bound 8 = 81 
Bound 9 = 90
Bound 10 = 100 
于 2013-08-05T01:49:14.127 回答