codeforces #329 div 2 B. Anton and Lines(几何)

B. Anton and Lines
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

The teacher gave Anton a large geometry homework, but he didn’t do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = ki·x + bi. It was necessary to determine whether there is at least one point of intersection of two of these lines, that lays strictly inside the strip between x1 < x2. In other words, is it true that there are1 ≤ i < j ≤ n and x‘, y‘, such that:

  • y‘ = ki * x‘ + bi, that is, point (x‘, y‘) belongs to the line number i;
  • y‘ = kj * x‘ + bj, that is, point (x‘, y‘) belongs to the line number j;
  • x1 < x‘ < x2, that is, point (x‘, y‘) lies inside the strip bounded by x1 < x2.

You can’t leave Anton in trouble, can you? Write a program that solves the given task.

Input

The first line of the input contains an integer n (2 ≤ n ≤ 100 000) — the number of lines in the task given to Anton. The second line contains integers x1 and x2 ( - 1 000 000 ≤ x1 < x2 ≤ 1 000 000) defining the strip inside which you need to find a point of intersection of at least two lines.

The following n lines contain integers kibi ( - 1 000 000 ≤ ki, bi ≤ 1 000 000) — the descriptions of the lines. It is guaranteed that all lines are pairwise distinct, that is, for any two i ≠ j it is true that either ki ≠ kj, or bi ≠ bj.

Output

Print “Yes” (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print “No” (without quotes).

Sample test(s)
input

output

input

output

input

output

input

output

Note

In the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it.

好吧。。。人蠢。。所以没想出来。。

其实画个图就能明白。。。如果两条直线相交在x1,x2之间。。

那么两条直线,分别于x1,x2的交点。。一定是一对逆序对。。。

我们可以得到每条直线在x1,x2的交点的纵坐标。。

然后按照与x1交点的纵坐标降序排。

另外一个比较重要的的是,判断是否有逆序对,只需要判断相邻的就行了。

可以用如下证明(不知道有什么更容易想的办法?)

假设直线i与直线i+k(k>=2)相交,那么直线i与直线i+j(1=

那么li[i].secli[i+k].sec

所以li[i+j].sec>li[i].sec>li[i+k].sec

那么直线i+j一定与i+k相交

当j=k-1时,i+j与i+k相邻。

也就是说…如果任意直线i与j相交…我们总可以转化成一对相邻的直线相交。

因此只判断相邻直线的相交就可以。

画图也能看出来。

最后一点是,要开long long 。

View Code

 

 

                                                                                                                                                                                                 

作者: CrazyKK

ex-ACMer@hust,researcher@sensetime

说点什么

您将是第一位评论人!

提醒
wpDiscuz