1 条题解
-
0
C++ :
#include <cstdio> #include <algorithm> using namespace std; struct Prog { int s, e; }; static Prog p[105]; bool cmp(const Prog &x, const Prog &y){ return x.e < y.e; } /* 多组数据,n=0 结束。求最多能完整看完的节目: 按结束时间升序贪心,相邻首尾相接不算冲突(下一个 start >= 上一个 end)。 */ int main(){ int n; while(scanf("%d", &n) == 1 && n){ for(int i = 0; i < n; i++) scanf("%d %d", &p[i].s, &p[i].e); sort(p, p + n, cmp); int last = -1, ans = 0; for(int i = 0; i < n; i++){ if(p[i].s >= last){ ans++; last = p[i].e; } } printf("%d\n", ans); } return 0; }
- 1
信息
- ID
- 2860
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者