由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 大家帮忙看看这一道F家的题目?看看都有么有思路?
相关主题
问F家一道题contract position有什么特别的吗
问道难的scheduling问题CS选课求建议
facebook interview questionHiring Graduate Layout Engineer
A facebook interview question一道越野赛跑问题,附解答
说说某著名软件公司的onsite面试epi 还是 The Algorithm Design Manual
Microsoft 一道算法题Algorithm in C++大家怎么准备?
Two problems about AlgorithmAlgorithms的书
烙印职场迷宫凯旋ALGORITHM面试的时候可以用STL吗
相关话题的讨论汇总
话题: employee话题: day话题: algorithm话题: event话题: apparently
进入JobHunting版参与讨论
1 (共1页)
i*********7
发帖数: 348
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).
H****r
发帖数: 2801
2
"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).

i*********7
发帖数: 348
3
我也不知道。。。careercup上面就这么写的。
我怎么有印象其实这应该是一道np问题?

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

p********s
发帖数: 37
4
收回前言,大牛们帮忙看看下面这个思路中不中,没证明:
首先显然有性质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次的情况似乎可以推广得到,多记个数就行。
C***U
发帖数: 2406
5
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).

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

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

w****x
发帖数: 2483
7
greedy啦, 就是最大event安排问题
f*********2
发帖数: 25
8
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).

t********e
发帖数: 344
9
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.

i***d
发帖数: 28
10

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

【在 t********e 的大作中提到】
: In your example the answer is 3,4,5,6,7,8,9
1 (共1页)
进入JobHunting版参与讨论
相关主题
面试的时候可以用STL吗说说某著名软件公司的onsite面试
A Video algorithm job from a headhunter (转载)Microsoft 一道算法题
问一下,google 面试Two problems about Algorithm
Algorithm in C完整版下载烙印职场迷宫凯旋ALGORITHM
问F家一道题contract position有什么特别的吗
问道难的scheduling问题CS选课求建议
facebook interview questionHiring Graduate Layout Engineer
A facebook interview question一道越野赛跑问题,附解答
相关话题的讨论汇总
话题: employee话题: day话题: algorithm话题: event话题: apparently