解题思路:
注意事项:
参考代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Max = 100010;
vector<int> dingdan[Max];
int p[Max];
bool incache[Max];
int N,M,T;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N >> M >> T;
int ts,id;
for(int i = 1; i <= N; ++i)
{
dingdan[i].clear();
}
for(int i = 0; i < M; ++i)
{
cin >> ts >> id;
dingdan[id].push_back(ts);
}
int ans = 0;
for(int i = 1; i <= N; ++i)
{
int sz = dingdan[i].size();
if(sz == 0)
continue;
sort(dingdan[i].begin(),dingdan[i].end());
int now = dingdan[i][0];
int pre = now;
for(int j = 0; j < sz; ++j)
{
now = dingdan[i][j];
int cha = now - pre;
if(cha == 0 || cha == 1)
{
p[i] += 2;
if(p[i]>5)
{
incache[i] = true;
}
}
else
{
// 先减再加
p[i] -= cha-1;
if(p[i] < 0)
p[i] = 0;
if(p[i] <= 3)
{
incache[i] = false;
}
p[i] += 2;
if(p[i]>5)
{
incache[i] = true;
}
}
pre = now;
}
int cha = T - pre;
if(cha > 0)
{
p[i] -= cha;
if(p[i] <= 3)
incache[i] = false;
}
if(incache[i])
ans ++;
}
cout << ans;
return 0;
}
0.0分
3 人评分