题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2037
其实题目跟会场会议安排是一样的,只是上一个节目的结束时间可以与下一个节目开始的时间相同,一次水过,如果不懂的可以去看NYOJ 14 会场会议安排。
代码:
#include<stdio.h> #include<algorithm> using namespace std; struct hy { int begin; int end; }w[1001]; bool comp(hy x,hy y) { if(x.end<y.end) return true; return false; } int main() { int n,i,p,count; while(~scanf("%d",&n)&&n) { for(i=0;i<n;i++) { scanf("%d %d",&w[i].begin,&w[i].end); } sort(w,w+n,comp); p=0;count=1; for(i=1;i<n;i++) { if(w[i].begin>=w[p].end) { count++; p=i; } } printf("%d\n",count); } return 0; }
本文介绍了 HDU 2037 的算法题解,该问题与会场会议安排类似,核心在于通过排序和遍历来找出能够连续播放的最多节目数量。文中提供了一个简洁的 C++ 实现代码。
429

被折叠的 条评论
为什么被折叠?



