赞
踩
每次选择结束时间最早的活动
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 5e5 + 10;
- int n;
- struct pp
- {
- int a, b;
- } p[N];
- bool cmp(pp x, pp y)
- {
- return x.b < y.b;
- }
- int ans = 0;
-
- int main()
- {
- cin >> n;
- for (int i = 1; i <= n; i++)
- {
- cin >> p[i].a >> p[i].b;
- }
- sort(p + 1, p + n + 1, cmp);
- int temp = 0;
- for (int i = 1; i <= n; i++)
- {
- if (p[i].a >= temp)
- {
- temp= p[i].b;
- ans++;
- }
- }
- cout << ans;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。