Homework Introduction
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
// 结构体
// 定义了一个结构体类型 node
// 这个类型里面又有两个子元素类型 s 和 t
struct node {
int s, t;
};
node a[N]; // a[i] 对应一个结构体
bool cmp(node a, node b) {
return a.t < b.t;
}
int n, ans;
int main() {
cin >> n;
// 结构体里面访问某个具体的元素要用 ·
for (int i = 1; i <= n; i++)
cin >> a[i].s >> a[i].t;
sort(a + 1, a + 1 + n, cmp); // 制定排序规则
int last = a[1].t;
ans = 1;
for (int i = 2; i <= n; i++) {
if (a[i].s >= last) { // 如果当前活动的时间大于等于上一个,可以安排
ans++;
last = a[i].t;
}
}
cout << ans;
return 0;
}
Problem
- Status
- Done
- Problem
- 47
- Open Since
- 2025-9-15 0:00
- Deadline
- 2025-11-28 23:59
- Extension
- 24 hour(s)