会议安排问题(贪心算法)
2013-10-13 22:52
381 查看
#include<stdio.h> #define N 11 struct Meeting{ int id; int begin; int end; }; int main() { Meeting list ,temp; int k=0; for(int i=0;i<N;i++) { //Input meeting ID, begin time and end time. scanf("%d %d %d",&list[i].id,&list[i].begin,&list[i].end); } //Sort meetings according to the end time. for(int i=0;i<N-1;i++) { for(int j=0;j<N-i-1;j++) { if(list[j].end>list[j+1].end) { temp = list[j]; list[j] = list[j+1]; list[j+1] = temp; } } } for(int i=0;i<N;i++) { if(i==0) { printf("Meeting ID: %d Begin: %d End: %d\n",list[i].id,list[i].begin,list[i].end); } else { //会议结束的时间尽的可能早,但又不能冲突。 if(list[i].begin>=list[k].end) { printf("Meeting ID: %d Begin: %d End: %d\n",list[i].id,list[i].begin,list[i].end); k=i; } } } getchar(); }
相关文章推荐
- 贪心算法 WOODEN STICKS 实例代码
- 贪心算法
- ACM常用算法
- HDU 1009
- POJ 1328.Radar Installation
- hdoj_2021 发工资咯:)
- zoj_1076 Gene Assembly
- poj_1065 Wooden Sticks
- uva 10714
- 贪心算法
- ACM - 暑期第二天:贪心算法 及 字典树
- HDU ACM 1050 Moving Tables
- HDU1009 FatMouse' Trade
- HDU4544 湫湫系列故事——消灭兔子
- Shoemaker's Problem
- 贪心算法-求区间至少连续k的最大和
- Huffman算法(最优二叉树)
- 贪心算法解决0 1背包问题
- 贪心算法求解哈弗曼编码
- POJ2287 田忌赛马---贪心算法