Magic Way

查看题解 查看答案
题目描述
Time Limit: 1000 ms
Memory Limit: 256 mb

     This a magical country where the wizard  use magic to help people. But the country's roads are so narrow that they are almost as wide as one car, so two cars can't drive side by side. Wizards use magic on ths road so that  when two cars overlapped, they would penetrate each other. In addition, the speed of vehicles on the road is 1m/s and the direction can only be 1 and -1.

     Unfortunately, there are some people in  the country who call themselves black magicians. The black magicians intend to do some damage. They cast a spell in a castle, making the magic in the middle of the castle ineffective.That is, if two cars overlap in the middle of the castle, the two cars will collide.Not only that, black magicians can also cause all vehicles to be able to simultaneously enchant in a certain direction, with the maximum enchant speed being wmax.

     Now,  the road is regarded as a one-dimensional coordinate axis, with the positive center of castle as the origin of the one-dimensional coordinate axis.There are n vehicles on the coordinate axis, and the coordinate of the ith vehicle on the coordinate axis is Xi. The length of each vehicle is l, that is to say, the coordinate of the ith vehicle is (Xi, Xi + L), and it is ensured that no two vehicles have the same coverage area at the beginning.

     Now the black magicians want to know how many pairs of cars may collide at the speed of W (- Wmax < = w < = Wmax).

 

输入输出格式
输入描述:
The first line contains three space-separated integers n, l, and wmax(1 ≤ n ≤ 1e5, 1 ≤ l,wmax ≤1e8), respectively, the number of cars, the length of each car, and the maximum holding speed. The ith of the following n lines contains the two space-separated integers xi and vi (−1e8 ≤ xi ≤ 1e8, vi ∈ {−1,1} ) representing the initial position and speed of the ith car. Input guarantees that all 1≤ I <j ≤ n, |xi−xj| ≥ l.
输出描述:
Output an integer indicating how many pairs of cars will collide at the same time at a certain speed.
输入输出样例
输入样例#:
5 1 2
-2 1
2 1
3 -1
5 -1
7 -1
输出样例#:
复制
4
提示
(1,3) at 2.5s, the collision occurred at the origin at the blessing speed of w= -0.4; (1,4). At 3.5s, the collision occurred at the origin at a holding speed of w=−0.6. (1,5). At 4.5s, at the blessing speed of w= -0.7, the collision occurred at the origin. (2,5) at 2.5s, at the holding speed of w= -2, the collision occurred at the origin;
编辑器外观×
主题
字号 16px
背景
登录后免费刷此题

提交代码后在此处可查看状态