[编程之美]安排见面会
2012-03-23 11:12
148 查看
View Code
Build a sorted array consisting of start time and finish time of each event traverse if(element_type==begin) add a new room else delete a room
//Get the first finish time of rooms int getFirst(int n,int* RoomFinish) { int first=0; for(int i=1;i<n;++i) if(RoomFinish[i]<RoomFinish[first]) first=i; return first; } int Greedy(int* start,int* end,int n,int* RoomFinish) { //Add a room for the first event int count=1; RoomFinish[count-1]=end[0]; for(int i=1;i<n;++i) { int first=getFirst(count,RoomFinish); //if the start time of this event is before the first finish time of rooms,we must add a new room for it if(start[i]<RoomFinish[first]) { count++; RoomFinish[count-1]=end[i]; } //if the start time of this event is after the first finish time of rooms, we just substitute the event with this event else { RoomFinish[first]=end[i]; } } return count; }
相关文章推荐
- 编程之美-----高效率地安排见面会
- 编程之美----高效率地安排见面会----贪心策略
- 读书笔记之编程之美 - 1.9 高效率地安排见面会
- 【编程之美】高效率的安排见面会
- 编程之美 - 安排见面会问题
- 编程之美 set 15 高效率地安排见面会
- 【编程之美】高效率的安排见面会
- 高效率安排见面会问题(比编程之美的解法复杂度低n-1个数量级)
- 编程之美--1.9高效率的安排见面会(解法二python)
- 编程之美之高效安排见面会
- 编程之美----高效率地安排见面会----贪心策略
- 驯服Trivia烂代码:bjdp.org第13次编程道场议程安排
- 编程之美:高效率地安排见面会
- 高效地安排见面会扩展问题
- 重新开始战斗07-编程之美-高效见面会
- 《编程之美》1.9:高效率的安排见面会的一个解法
- 算法与编程实践内容安排 统计字母的使用频率
- 【编程素质】活动安排问题(会场安排问题、图着色问题)
- 算法与编程实践内容安排 进制转换
- 第1章 游戏之乐——高效率地安排见面会