gpt4 book ai didi

algorithm - 在日期范围内分配约会

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:03:42 25 4
gpt4 key购买 nike

我正在尝试生成一些测试数据。

假设我需要在一个日期范围内分配 1000 个约会。

现在我需要分配这些约会,使得月底每天的约会数量是月初的两倍。预约的增加需要以一致的速度增加。

因此,例如,如果该月的第一天有 5 个约会,到月底,我们每天将获得 10 个约会。

预约只能在工作日进行。

是否有合适的算法可以帮助我以这种方式分配这些日期?

编辑

这是迄今为止我得到的最好的,灵感来自 Henriks 解决方案:

    private int GetNumForCurrentDate (DateTime date)
{
int daysInMonth = DateTime.DaysInMonth ( date.Year, date.Month );

// x is the number of appointments on the first day
double firstDay = this._NumPerMonth / ( ( ( ratio + 1 ) / 2 ) * daysInMonth );

// x * ratio is the number of appointments on the last day.
double lastDay = firstDay * ratio;

// Interpolate a value between the first and last days
double exactNumOnThisDay = firstDay + ( lastDay - firstDay ) * ( (double)date.Day / (double)daysInMonth );
int numOnThisDay = Convert.ToInt32 ( Math.Truncate ( exactNumOnThisDay ) );

// Accumulate any overflow
this._Overflow += exactNumOnThisDay - numOnThisDay;
if ( this._Overflow > 1 )
{
// Shove the overflow into our number when it gets into whole number teritory
numOnThisDay++;
this._Overflow--;
}

return numOnThisDay;
}

它返回在给定日期的特定日期分配的天数。它处理分离每个月的分配并处理舍入溢出,但它不是很完美,它用完了最后一天的分配天数,但现在已经足够好了,我已经没有时间来完善它了。 .

最佳答案

第一天 x 次约会,最后一天 2 次,所以平均 1.5 次。当有 y 个工作日时,x 为 1000/(1.5y)。所以第一天 667/年,最后一天 1333/年,对中间的日子进行插值

关于algorithm - 在日期范围内分配约会,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2244530/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com