M04100:进程检测
http://cs101.openjudge.cn/practice/04100
cpp
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct Node
{
int s, d;
};
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int k;
cin >> k;
while (k--)
{
int n;
cin >> n;
vector<Node> p(n);
for (int i = 0; i < n; i++)
cin >> p[i].s >> p[i].d;
int testCounter = 0;
sort(p.begin(), p.end(), [](Node &a, Node &b) -> bool
{ return a.s < b.s; });
int it = 0;
while (it < n)
{
int j = it;
int maxs = p[it].s, mind = p[it].d;
while (j < n && p[j].s >= maxs && p[j].s <= mind)
{
maxs = max(maxs, p[j].s);
mind = min(mind, p[j].d);
j++;
}
it = j;
testCounter++;
}
cout << testCounter << '\n';
}
return 0;
}