CF1463C.Busy Robot
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You have a robot that can move along a number line. At time moment 0 it stands at point 0.
You give n commands to the robot: at time ti seconds you command the robot to go to point xi. Whenever the robot receives a command, it starts moving towards the point xi with the speed of 1 unit per second, and he stops when he reaches that point. However, while the robot is moving, it ignores all the other commands that you give him.
For example, suppose you give three commands to the robot: at time 1 move to point 5, at time 3 move to point 0 and at time 6 move to point 4. Then the robot stands at 0 until time 1, then starts moving towards 5, ignores the second command, reaches 5 at time 6 and immediately starts moving to 4 to execute the third command. At time 7 it reaches 4 and stops there.
You call the command i successful, if there is a time moment in the range [ti,ti+1] (i. e. after you give this command and before you give another one, both bounds inclusive; we consider tn+1=+∞) when the robot is at point xi. Count the number of successful commands. Note that it is possible that an ignored command is successful.
你有一个机器人,可以在数轴上移动。在时刻 0,它位于点 0。
你向机器人发出 n 条指令:在时刻 ti(单位:秒),你命令机器人前往点 xi。每当机器人接收到一条指令时,它立即以 1 单位/秒的速度朝点 xi 移动,并在到达该点后停止。然而,在机器人移动过程中,它会忽略你发出的所有其他指令。
例如,假设你向机器人发出三条指令:在时刻 1 前往点 5,在时刻 3 前往点 0,在时刻 6 前往点 4。那么机器人从时刻 0 到 1 一直静止于 0;在时刻 1 开始向 5 移动,忽略第二条指令,在时刻 6 到达 5,并立即开始执行第三条指令、向 4 移动;在时刻 7 到达 4 并停止。
若存在某个时刻属于区间 [ti,ti+1](即在你发出第 i 条指令之后、发出下一条指令之前,两端均包含;我们约定 tn+1=+∞),使得机器人恰位于点 xi,则称第 i 条指令是成功的。请统计成功指令的数量。注意:被忽略的指令也可能是成功的。
输入格式
The first line contains a single integer t (1≤t≤1000) — the number of test cases. The next lines describe the test cases.
The first line of a test case contains a single integer n (1≤n≤105) — the number of commands.
The next n lines describe the commands. The i-th of these lines contains two integers ti and xi (1≤ti≤109, −109≤xi≤109) — the time and the point of the i-th command.
The commands are ordered by time, that is, ti<ti+1 for all possible i.
The sum of n over test cases does not exceed 105.
第一行包含一个整数 t(1≤t≤1000),表示测试用例的数量。接下来的行描述各个测试用例。
每个测试用例的第一行包含一个整数 n(1≤n≤105),表示命令的数量。
接下来的 n 行描述这些命令。其中第 i 行包含两个整数 ti 和 xi(1≤ti≤109,−109≤xi≤109),分别表示第 i 个命令的时间和位置。
命令按时间升序排列,即对所有可能的 i,均有 ti<ti+1。
所有测试用例的 n 值之和不超过 105。
输出格式
For each testcase output a single integer — the number of successful commands.
对于每个测试用例,输出一个整数——成功命令的数量。
输入输出样例
输入#1
8 3 1 5 3 0 6 4 3 1 5 2 4 10 -5 5 2 -5 3 1 4 1 5 1 6 1 4 3 3 5 -3 9 2 12 0 8 1 1 2 -6 7 2 8 3 12 -9 14 2 18 -1 23 9 5 1 -4 4 -7 6 -1 7 -3 8 -7 2 1 2 2 -2 6 3 10 5 5 8 0 12 -4 14 -7 19 -5
输出#1
1 2 0 2 1 1 0 2
说明/提示
The movements of the robot in the first test case are described in the problem statement. Only the last command is successful.
In the second test case the second command is successful: the robot passes through target point 4 at time 5. Also, the last command is eventually successful.
In the third test case no command is successful, and the robot stops at −5 at time moment 7.
Here are the 0-indexed sequences of the positions of the robot in each second for each testcase of the example. After the cut all the positions are equal to the last one:
- [0,0,1,2,3,4,5,4,4,…]
- [0,0,1,2,3,4,5,5,5,5,5,4,3,2,1,0,−1,−2,−3,−4,−5,−5,…]
- [0,0,0,−1,−2,−3,−4,−5,−5,…]
- [0,0,0,0,1,2,3,3,3,3,2,2,2,1,0,0,…]
- [0,0,1,0,−1,−2,−3,−4,−5,−6,−6,−6,−6,−7,−8,−9,−9,−9,−9,−8,−7,−6,−5,−4,−3,−2,−1,−1,…]
- [0,0,−1,−2,−3,−4,−4,−3,−2,−1,−1,…]
- [0,0,1,2,2,…]
- [0,0,0,0,1,2,3,4,5,6,7,8,9,10,10,9,8,7,6,5,4,3,2,1,0,−1,−2,−3,−4,−5,−6,−7,−7,…]
第一个测试用例中机器人的运动过程已在题目描述中给出,仅最后一条指令成功执行。
第二个测试用例中,第二条指令成功执行:机器人在时刻 5 经过目标点 4;此外,最后一条指令最终也成功执行。
第三个测试用例中,没有任何指令成功执行,机器人于时刻 7 停止在位置 −5。
以下是示例中各测试用例对应的机器人在每一秒(从 0 开始编号)所处位置的序列。截断后,所有后续位置均等于最后一个实际变化的位置:
- [0,0,1,2,3,4,5,4,4,…]
- [0,0,1,2,3,4,5,5,5,5,5,4,3,2,1,0,−1,−2,−3,−4,−5,−5,…]
- [0,0,0,−1,−2,−3,−4,−5,−5,…]
- [0,0,0,0,1,2,3,3,3,3,2,2,2,1,0,0,…]
- [0,0,1,0,−1,−2,−3,−4,−5,−6,−6,−6,−6,−7,−8,−9,−9,−9,−9,−8,−7,−6,−5,−4,−3,−2,−1,−1,…]
- [0,0,−1,−2,−3,−4,−4,−3,−2,−1,−1,…]
- [0,0,1,2,2,…]
- [0,0,0,0,1,2,3,4,5,6,7,8,9,10,10,9,8,7,6,5,4,3,2,1,0,−1,−2,−3,−4,−5,−6,−7,−7,…]
输入解题思路,AI测评打分。不知道怎么写?