首页 > 其他 > 详细

一本通 1.1 例 1【活动安排】

时间:2020-10-25 17:45:01      阅读:20      评论:0      收藏:0      [点我收藏+]

题目linkhttps://loj.ac/problem/10000

贪心即可,将活动按右端点排序,排序后能选则选。

 1 #include <bits/stdc++.h>
 2 #define INF 0x3f3f3f3f
 3 using namespace std;
 4 int n, ans, last;
 5 struct Str {int l, r;}stu[1010];
 6 int cmp(Str a, Str b) {return a.r < b.r;}
 7 int main()
 8 {
 9     scanf("%d", &n); for(int i = 1; i <= n; ++i) scanf("%d %d", &stu[i].l, &stu[i].r);
10     sort(stu + 1, stu + n + 1, cmp);
11     for(int i = 1; i <= n; ++i)
12         if(stu[i].l >= last) 
13             last = stu[i].r, ++ans;
14     printf("%d", ans);
15     return 0;
16 } 

 

一本通 1.1 例 1【活动安排】

原文:https://www.cnblogs.com/qqq1112/p/13873108.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!