题目1434:今年暑假不AC
思路:
用结束时间排序,如果当前时间<=开始时间,ans++;
代码:
#include <stdio.h>
#include <algorithm>
using std::sort;
#define N 100
struct Program
{
int s;
int e;
}buf[N];
bool cmp(Program a, Program b)
{
return a.e < b.e;
}
int main()
{
int n;
while (scanf("%d", &n) != EOF && n != 0)
{
for (int i = 0; i < n; i++)
scanf("%d%d", &buf[i].s, &buf[i].e);
sort(buf, buf + n, cmp);
int currentTime = 0;
int ans = 0;
for (int i = 0; i < n; i++)
{
if (currentTime <= buf[i].s)
{
ans++;
currentTime = buf[i].e;
}
}
printf("%d\n", ans);
}
return 0;
}