Codeforces 989D A Shade of Moonlight 二分+数学

D. A Shade of Moonlight
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

The sky can be seen as a one-dimensional axis. The moon is at the origin whose coordinate is 00.

There are nn clouds floating in the sky. Each cloud has the same length ll. The ii-th initially covers the range of (xi,xi+l)(xi,xi+l) (endpoints excluded). Initially, it moves at a velocity of vivi, which equals either 11 or 1−1.

Furthermore, no pair of clouds intersect initially, that is, for all 1i<jn1≤i<j≤n|xixj|l|xi−xj|≥l.

With a wind velocity of ww, the velocity of the ii-th cloud becomes vi+wvi+w. That is, its coordinate increases by vi+wvi+w during each unit of time. Note that the wind can be strong and clouds can change their direction.

You are to help Mino count the number of pairs (i,j)(i,j) (i<ji<j), such that with a proper choice of wind velocity ww not exceeding wmaxwmax in absolute value (possibly negative and/or fractional), the ii-th and jj-th clouds both cover the moon at the same future moment. This wwdoesn't need to be the same across different pairs.

Input

The first line contains three space-separated integers nnll, and wmaxwmax (1n1051≤n≤1051l,wmax1081≤l,wmax≤108) — the number of clouds, the length of each cloud and the maximum wind speed, respectively.

The ii-th of the following nn lines contains two space-separated integers xixi and vivi (108xi108−108≤xi≤108vi{1,1}vi∈{−1,1}) — the initial position and the velocity of the ii-th cloud, respectively.

The input guarantees that for all 1i<jn1≤i<j≤n|xixj|l|xi−xj|≥l.

Output

Output one integer — the number of unordered pairs of clouds such that it's possible that clouds from each pair cover the moon at the same future moment with a proper choice of wind velocity ww.

Examples
input
Copy
5 1 2
-2 1
2 1
3 -1
5 -1
7 -1
output
Copy
4
input
Copy
4 10 1
-20 1
-10 -1
0 1
10 -1
output
Copy
1
Note

In the first example, the initial positions and velocities of clouds are illustrated below.

The pairs are:

  • (1,3)(1,3), covering the moon at time 2.52.5 with w=0.4w=−0.4;
  • (1,4)(1,4), covering the moon at time 3.53.5 with w=0.6w=−0.6;
  • (1,5)(1,5), covering the moon at time 4.54.5 with w=0.7w=−0.7;
  • (2,5)(2,5), covering the moon at time 2.52.5 with w=2w=−2.

Below is the positions of clouds at time 2.52.5 with w=0.4w=−0.4. At this moment, the 11-st and 33-rd clouds both cover the moon.

In the second example, the only pair is (1,4)(1,4), covering the moon at time 1515 with w=0w=0.

Note that all the times and wind velocities given above are just examples among infinitely many choices.

思路上大体上就是二分了,显然只有初始速度方向相反的云才能相遇,所以猜测应该就是将方向不同的云记录在两个数组里,然后枚举其中一个,二分另一个。然而应该用什么指标来判断云是否能相遇呢?到这儿骚操作就来了,我们想象没有风在吹,月亮自己在跑,如下图。


橙色代表月亮的轨迹,蓝色代表云的轨迹。如果两个蓝条能在橙色部分相遇,那么就说明有一对云是符合要求的。根据w必定大于1,可知橙色线和横轴夹角不得大于45°。那就保证蓝条相交得到的菱形,上面的顶点在橙色区域里,因此xjxi+l2>|xjxi+l2+xi|/w。

从第一个满足这个条件的云开始,往后的云都满足这个条件,我们把它加在结果里。

代码奇丑无比,不贴了。




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值