Redian新闻
>
FB上amazon 25 off 75的没了
avatar
FB上amazon 25 off 75的没了# Money - 海外理财
i*7
1
You are given N ranges of date offsets when N employees are present in an
organization. Something like
1-4 (i.e. employee will come on 1st, 2nd, 3rd and 4th day )
2-6
8-9
..
1-14
You have to organize an event on minimum number of days such that each
employee can attend the event at least twice. Write an algorithm (there is
apparently an O(n) algorithm for this).
avatar
H*7
2
唉呀
avatar
H*r
3
"there is apparently an O(n) algorithm for this"
这个结论哪里来的?

【在 i*********7 的大作中提到】
: You are given N ranges of date offsets when N employees are present in an
: organization. Something like
: 1-4 (i.e. employee will come on 1st, 2nd, 3rd and 4th day )
: 2-6
: 8-9
: ..
: 1-14
: You have to organize an event on minimum number of days such that each
: employee can attend the event at least twice. Write an algorithm (there is
: apparently an O(n) algorithm for this).

avatar
i*7
4
我也不知道。。。careercup上面就这么写的。
我怎么有印象其实这应该是一道np问题?

【在 H****r 的大作中提到】
: "there is apparently an O(n) algorithm for this"
: 这个结论哪里来的?

avatar
p*s
5
收回前言,大牛们帮忙看看下面这个思路中不中,没证明:
首先显然有性质1:
对于两个employee ij有区间[ai,bi][aj,bj]满足ai<=aj<=bj<=bi,则可以不去考虑员
工i,满足j即可满足i。
因此如果对所有需要考虑的区间进行排序后,对于i和i+1有性质2:
要么ai<=aj<=bi<=bj(相交而不包含)
要么ai<=bi<=aj<=bj(不相交)
这里根据题目情景考虑,总日期数不会太多,而员工数可能很多,因此可以O(n)时间对
所有区间的ai进行排序,然后O(n)时间消除所有性质1中的包含情况,然后:
如果每个员工只出席一次的话,那其实只要贪心就好。即对当前员工i,让其在bi(最
后一天)开会,然后顺序的让与[ai,bi]相交的i+1,i+2..都在同一天开会,直到无法满
足时,再重复此步骤。这个也是o(n)
而出席2次的情况似乎可以推广得到,多记个数就行。
avatar
C*U
6
sorting + greedy就可以做了
先把所有人根据末尾的时间排序 用O(nlogn)时间
然后从头开始 为每个人选取最晚的时间
比如第一个人是1-4, 那么选取3-4两天办会议
如果有别的人和这两天重合,那么就可以把这个去掉了
否则为这个人选取最晚的可能的时间

【在 i*********7 的大作中提到】
: You are given N ranges of date offsets when N employees are present in an
: organization. Something like
: 1-4 (i.e. employee will come on 1st, 2nd, 3rd and 4th day )
: 2-6
: 8-9
: ..
: 1-14
: You have to organize an event on minimum number of days such that each
: employee can attend the event at least twice. Write an algorithm (there is
: apparently an O(n) algorithm for this).

avatar
s*a
7
找出所有人最晚的到达时间T1,最早的离开时间T2一O(N),然后选[T2-1, T1+1]为开会
时间如果T1>=T2-1,否则选[T1, T1+1]为开会时间。

【在 C***U 的大作中提到】
: sorting + greedy就可以做了
: 先把所有人根据末尾的时间排序 用O(nlogn)时间
: 然后从头开始 为每个人选取最晚的时间
: 比如第一个人是1-4, 那么选取3-4两天办会议
: 如果有别的人和这两天重合,那么就可以把这个去掉了
: 否则为这个人选取最晚的可能的时间

avatar
w*x
8
greedy啦, 就是最大event安排问题
avatar
f*2
9
I do not quite understand this problem.
For example,
1-4 (employee Ann comes on Day 1, 2, 3, 4)
2-6 (employee Bob comes on Day 2, 3, 4, 5, 6)
8-9 (employee Charles comes on Day 8, 9)
1-14 (employee David comes on 1, 2, ..., 14).
There is no way you can find a day when every employee agree on.

【在 i*********7 的大作中提到】
: You are given N ranges of date offsets when N employees are present in an
: organization. Something like
: 1-4 (i.e. employee will come on 1st, 2nd, 3rd and 4th day )
: 2-6
: 8-9
: ..
: 1-14
: You have to organize an event on minimum number of days such that each
: employee can attend the event at least twice. Write an algorithm (there is
: apparently an O(n) algorithm for this).

avatar
t*e
10
In your example the answer is 3,4,5,6,7,8,9

【在 f*********2 的大作中提到】
: I do not quite understand this problem.
: For example,
: 1-4 (employee Ann comes on Day 1, 2, 3, 4)
: 2-6 (employee Bob comes on Day 2, 3, 4, 5, 6)
: 8-9 (employee Charles comes on Day 8, 9)
: 1-14 (employee David comes on 1, 2, ..., 14).
: There is no way you can find a day when every employee agree on.

avatar
i*d
11

是不是 3,4,8,9 就好啊?

【在 t********e 的大作中提到】
: In your example the answer is 3,4,5,6,7,8,9
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。