由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 问道题
相关主题
问一道题(2)SQL 面试问题
关于什么时候可以用贪心算法求找零问题即将入职亚麻的小硕求教一下今后发展方向
想请教一下动态规划和贪心算法的区别amazon电面 + facebook 电面
Analytical chemist opening in south bay自己设计的一道面试题
Hiring Algorithm Expert / Data Scientist (转载)A facebook interview question
Operation Research Applied Scientist 加州备考google onsite, 讨论堆排序的时间复杂度
amazon 1st phone interview请教一道google的数组遍历题
[Job Opening] 3D Engine Developer - Physics and Low Level OptimizationGoogle面试怎么这么难啊,LG很难过,我该怎么劝他呢? (转载)
相关话题的讨论汇总
话题: int话题: max话题: greedy话题: getmax话题: list
进入JobHunting版参与讨论
1 (共1页)
g******0
发帖数: 221
1
Given a list of presentations with begin and end time that all need to
use a conference room. We want to optimize the utilization of the room
by allowing maximum hours of the conference room being used.
Note: Not optimizing for the maximum number of presentations (This
would be the greedy algorithm from the CLRS book).
Any idea?
d*******d
发帖数: 2050
2
I guess dp will do
g**e
发帖数: 6127
3
背包问题

【在 g******0 的大作中提到】
: Given a list of presentations with begin and end time that all need to
: use a conference room. We want to optimize the utilization of the room
: by allowing maximum hours of the conference room being used.
: Note: Not optimizing for the maximum number of presentations (This
: would be the greedy algorithm from the CLRS book).
: Any idea?

c*******n
发帖数: 63
4
could somebody prove that we can generate an optimal solution if occupied
hours (end time - begin time) are used for greedy choices?
s*****y
发帖数: 897
5
[0,2] [3,12][14,15] [3,7][8,15]
greedy will be [0,2] [3,12][14,15]
but best should be [0,2][3,7][8,15]

【在 c*******n 的大作中提到】
: could somebody prove that we can generate an optimal solution if occupied
: hours (end time - begin time) are used for greedy choices?

c*******n
发帖数: 63
6
Nice work!
then we should try DP

【在 s*****y 的大作中提到】
: [0,2] [3,12][14,15] [3,7][8,15]
: greedy will be [0,2] [3,12][14,15]
: but best should be [0,2][3,7][8,15]

g**********y
发帖数: 14569
7
写了一个ugly的实现,想法是把presentation按结束时间排序。最后结束时间T,M[0..
T]记录时间0..t的最大利用值。
M[A(n,1)] = max{A(n,1)-A(n,0)+max(M[0..A(n,0)]), max(M[0..A(n,1)])}
程序应该可以简化,要输出选择的presentation, 数据结构也要改。
public void maxUse(List list) {
Collections.sort(list, new Comparator() {
public int compare(int[] a, int[] b) {
return a[1] - b[1];
}
});

int N = list.size();
int T = list.get(N-1)[1];
int[] max = new int[T+1];

for (int i=0; i int[] a = list.get(i);
int v1 = getMax(max, a[1]);
int v2 = a[1] - a[0] + getMax(max, a[0]-1);
max[a[1]] = Math.max(v1, v2);
}

System.out.println(max[T]);
}

private int getMax(int[] max, int t) {
for (int i=t; i>=0; i--) {
if (max[i] > 0) return max[i];
}
return 0;
}
g******0
发帖数: 221
8
Yes, true dat!

【在 d*******d 的大作中提到】
: I guess dp will do
m**q
发帖数: 189
9
程序有点没看懂,看描述复杂度是O(n^2)?
这题应该可以O(nlgn)的

..

【在 g**********y 的大作中提到】
: 写了一个ugly的实现,想法是把presentation按结束时间排序。最后结束时间T,M[0..
: T]记录时间0..t的最大利用值。
: M[A(n,1)] = max{A(n,1)-A(n,0)+max(M[0..A(n,0)]), max(M[0..A(n,1)])}
: 程序应该可以简化,要输出选择的presentation, 数据结构也要改。
: public void maxUse(List list) {
: Collections.sort(list, new Comparator() {
: public int compare(int[] a, int[] b) {
: return a[1] - b[1];
: }
: });

i**d
发帖数: 357
10

你这个greedy的取值条件不对。
应该是首先按照结束时间排序,然后greedy的每次取最早结束的presentation.
并且remove有overlap的presentation
按照这个例子应该首先排序成
[0,2],[3,7],[3,12],[8,15],[14,15]
首先取 [0,2]
然后取 [3,7] 并remove有overlap的[3,12]
最后取 [8,15], 并remove掉[14,15]
结果就是[0,2],[3,7],[8,15]

【在 s*****y 的大作中提到】
: [0,2] [3,12][14,15] [3,7][8,15]
: greedy will be [0,2] [3,12][14,15]
: but best should be [0,2][3,7][8,15]

H****s
发帖数: 247
11
这题就是 weighted interval scheduling 吧。 每个conference 的 weight就是它的
长度, 然后要求就总weight最大。 DP 就可解一般O(n^2), 使用特殊数据结构可以O(
nlgn)
d*******l
发帖数: 338
12
对,都不用什么特殊数据结构。按结束时间排序,d[i]表示前i个可以取到的最大时间
。对每个i,找到第一个满足start[i]>=end[j]的j,d[i]=max(d[i-1],d[j]+length[i]). 查找的过程用二分可以做到logn.

【在 H****s 的大作中提到】
: 这题就是 weighted interval scheduling 吧。 每个conference 的 weight就是它的
: 长度, 然后要求就总weight最大。 DP 就可解一般O(n^2), 使用特殊数据结构可以O(
: nlgn)

P**l
发帖数: 3722
13
dp吧
给个greedy的反例:
[0,2][3,4][1,100]
1 (共1页)
进入JobHunting版参与讨论
相关主题
Google面试怎么这么难啊,LG很难过,我该怎么劝他呢? (转载)Hiring Algorithm Expert / Data Scientist (转载)
究竟什么定义了DPOperation Research Applied Scientist 加州
做了一下 Google 的 Best Time to Buy and Sell Stock IIamazon 1st phone interview
问道题[Job Opening] 3D Engine Developer - Physics and Low Level Optimization
问一道题(2)SQL 面试问题
关于什么时候可以用贪心算法求找零问题即将入职亚麻的小硕求教一下今后发展方向
想请教一下动态规划和贪心算法的区别amazon电面 + facebook 电面
Analytical chemist opening in south bay自己设计的一道面试题
相关话题的讨论汇总
话题: int话题: max话题: greedy话题: getmax话题: list