如何使用位查找工作计划中的可用时间?

发布于 2025-01-01 03:07:42 字数 248 浏览 1 评论 0 原文

参考已经给出的另一个问题的答案:

https://stackoverflow.com/a/1609686/1183608

我是使用这个答案,但是我对计算acceptable_times数组的意义感到困惑。我想找出一天中的哪些时间(时间表)可用于特定的时间段长度,但上述答案中执行此操作的功能似乎不能满足这一点,除非我错过了某些内容。

In reference to an answer already given to another question:

https://stackoverflow.com/a/1609686/1183608

I am working with this answer, however I am confused on the meaningfulness of calculating the acceptable_times array. I want to find out at what times of the day (schedule) are available for the specific time slot length, but the function for doing so in the above answer does not seem to satisfy that, unless I have missed something.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

许仙没带伞 2025-01-08 03:07:43

grioja,您链接到的答案确实为您提供了一天中可用于您所需的时段长度的时间。繁忙/可用时间用位表示,例如:

1100001110

(这将是 30 个可用分钟,后面是 60 个繁忙分钟,后面是 45 个可用分钟,后面是 15 个繁忙时间。)然后您将得到一个二进制数,表示长度您要查找的可用时间段,例如:

111

(这意味着您要查找 45 分钟的可用时间段。)然后您尝试将这 2 个数字相互移动:

1100001110
0000000111

1100001110
0000001110

1100001110
0000011100

...等等,对于每个可能的相对移位长度。他在该答案中显示的 AND 运算确定“所需时隙长度”数字中的 1 是否与“可用次数”数字中的全 1 匹配。如果是的话,你已经找到了一个可以接受的时间。

顺便说一下,你可以用其他方式做同样的事情。例如,您可以用字符串中的字符表示繁忙/可用时间,并使用正则表达式查找所需长度的可用插槽。

请注意,如果可用/繁忙时隙列表很长,则这种通用方法(基本上只是“线性搜索”)将无法扩展。在这种情况下,还有其他方法会更快。

grioja, the answer you linked to does give you the times of day which are available for your desired slot length. The busy/available times are represented by bits, for example:

1100001110

(This would be 30 available minutes, followed by 60 busy minutes, followed by 45 available, followed by 15 busy.) Then you get a binary number which represents the length of the available time slot you want to find, say:

111

(This would mean you want to find a slot of 45 available minutes.) Then you try shifting the 2 numbers against each other:

1100001110
0000000111

1100001110
0000001110

1100001110
0000011100

...and so on, for every possible relative shift length. The AND operation he shows in that answer determines whether the 1's in the "desired slot length" number are matching all 1's in the "available times" number. If they are, you have found an acceptable time.

By the way, you could do the same thing in other ways. For example, you could represent busy/available times by characters in a string, and use a regular expression to find an available slot of the desired length.

Note that this general approach (which is basically just "linear search") will not scale if the list of available/busy time slots is very long. There are other approaches which will be much faster in that case.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文