题解:CF1463C Busy Robot
Bc2_Ch1ckenPr1nce · · 题解
Sol
其实是一个比较简单的模拟。
首先如果按时间线枚举肯定是不行的,会达到
所以我们可以枚举命令。
我们可以用两个变量
然后开始枚举命令,判断一下当前命令有没有被忽略。一个任务未被忽略当且仅当
如果这个命令未被忽略,那么就判断是否在下一个命令开始前是否能移动到(当且仅当
如果这个命令被忽略,那么就看看在
最后,一定要记得把
Code
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const int kMaxN = 1e5 + 10;
ll n, t[kMaxN], x[kMaxN], nt, nx, pos, ans;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int tt;
for (cin >> tt; tt; -- tt) {
cin >> n, t[n + 1] = 9e18;
for (int i = 1; i <= n; ++ i) {
cin >> t[i] >> x[i];
}
nt = nx = pos = ans = 0;
for (int i = 1; i <= n; ++ i) {
if (t[i] >= abs(pos - nx) + nt) {
pos = nx;
if (t[i + 1] - t[i] >= abs(nx - x[i])) {
++ ans;
}
nt = t[i], nx = x[i];
} else {
if (pos >= nx) {
if (pos - (t[i] - nt) >= x[i] && pos - (t[i + 1] - nt) <= x[i] && pos >= x[i] && nx <= x[i]) {
++ ans;
}
} else {
if (pos + (t[i] - nt) <= x[i] && pos + (t[i + 1] - nt) >= x[i] && pos <= x[i] && nx >= x[i]) {
++ ans;
}
}
}
}
cout << ans << '\n';
}
return 0;
}