CF EDU 100 C - Busy Robot
C - Busy Robot
模拟
nx : 当前发送当前这次命令时机器人的位置
ed:当前正在执行的操作的结束时间
d:当前的方向
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
const ll INF = 1e18;
int n;
ll t[N], x[N];
int main()
{
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int T;
cin >> T;
while(T--)
{
cin >> n;
for (int i = 1; i <= n; i++)
cin >> t[i] >> x[i];
t[n+1] = INF;
ll nx = 0, ed = 0, d = 0;
int cnt = 0;
for (int i = 1; i <= n; i++)
{
nx += (min(t[i], ed) - t[i-1]) * d;
if (t[i] >= ed)
{
ed = t[i] + abs(nx - x[i]);
d = (x[i] >= nx ? 1 : -1);
}
int l = nx, r = nx + (min(t[i+1], ed) - t[i]) * d;
if (l > r)
swap(l, r);
if (x[i] >= l && x[i] <= r)
cnt++;
}
cout << cnt << endl;
}
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 25岁的心里话