二维数组+排序
一定注意判断顺序
详细的看这个
C++ 代码
#include <bits/stdc++.h>
using namespace std;
int n, m, t, x, y;
vector<int> va;
bool is[100005];
int main()
{
ios ::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m >> t;
vector<int> vec[n + 1];
for (int i = 0; i < m; i++)
{
cin >> x >> y;
vec[y].push_back(x);
}
for (int i = 1; i < n + 1; i++)
{
if (vec[i].size() == 0)
continue;
int s = t - *max_element(vec[i].begin(), vec[i].end());
sort(vec[i].begin(), vec[i].end());
int ct = 2;
for (int j = 1; j < vec[i].size(); j++)
{
if (vec[i][j] - vec[i][j - 1] <= 1)
{
if (ct <= 3)
is[i] = 0;
ct += 2;
if (ct > 5)
{
is[i] = 1;
}
continue;
}
ct = ct - (vec[i][j] - vec[i][j - 1] - 1);
if (ct <= 3)
is[i] = 0;
if (ct < 0)
{
ct = 0;
is[i] = 0;
}
ct += 2;
if (ct > 5)
{
is[i] = 1;
}
}
if (is[i] || ct > 5)
{
if ((ct - s) > 3)
va.push_back(i);
}
}
cout << va.size();
return 0;
}