LINK

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 are 1 ≤ 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 ki, bi ( - 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
4
1 2
1 2
1 0
0 1
0 2
Output
NO
Input
2
1 3
1 0
-1 3
Output
YES
Input
2
1 3
1 0
0 2
Output
YES
Input
2
1 3
1 0
0 3
Output
NO
Note

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



Solution

两直线y1, y2交点横坐标在开区间(x1, x2)的充要条件:(y1(x1)-y2(x1))*(y1(x2)-y2(x2)) < 0

直线y对应二元组(y(x1), y(x2)),即直线y被x=x1, x=x2所截得的线段,将所有二元组按字典序排序只要判断是否有相邻两线段相交的情况即可。


Implementation

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL mod(1e9+); const int N(1e5+); int sign(LL x){
return x?x>?:-:;
} vector<pair<LL,LL>> seg; int main(){
ios::sync_with_stdio(false);
cin.tie(), cout.tie(); int n, x1, x2;
cin>>n>>x1>>x2;
LL k, b;
for(int i=; i<n; i++){
cin>>k>>b;
LL y1=k*x1+b, y2=k*x2+b;
seg.push_back({y1, y2});
} sort(seg.begin(), seg.end());
for(int i=; i<seg.size(); i++){
if(sign(seg[i].first-seg[i-].first)*sign(seg[i].second-seg[i-].second)<){
puts("YES");
return ;
}
}
puts("NO");
return ;
}

Codeforces 593B Anton and Lines的更多相关文章

  1. CF 593B Anton and Lines(水题)

    题意是给你n条直线,和x1,x2;问 在x1,x2之间(不包括在x1,x2上) 存不存在任意两条线的交点. 说思路,其实很简单,因为给的直线的条数很多,所以无法暴力求每两条直线的交点,那么就求每条直线 ...

  2. Codeforces Round #329 (Div. 2) B. Anton and Lines 逆序对

    B. Anton and Lines Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/593/pr ...

  3. Codeforces Round #329 (Div. 2)B. Anton and Lines 贪心

    B. Anton and Lines   The teacher gave Anton a large geometry homework, but he didn't do it (as usual ...

  4. Anton and Lines(思维)

    Anton and Lines time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  5. Codeforces 734E. Anton and Tree 搜索

    E. Anton and Tree time limit per test: 3 seconds memory limit per test :256 megabytes input:standard ...

  6. Codeforces 734D. Anton and Chess(模拟)

    Anton likes to play chess. Also, he likes to do programming. That is why he decided to write the pro ...

  7. Codeforces 734F Anton and School(位运算)

    [题目链接] http://codeforces.com/problemset/problem/734/F [题目大意] 给出数列b和数列c,求数列a,如果不存在则输出-1 [题解] 我们发现: bi ...

  8. [刷题]Codeforces 785D - Anton and School - 2

    Description As you probably know, Anton goes to school. One of the school subjects that Anton studie ...

  9. Codeforces 785D - Anton and School - 2 - [范德蒙德恒等式][快速幂+逆元]

    题目链接:https://codeforces.com/problemset/problem/785/D 题解: 首先很好想的,如果我们预处理出每个 "(" 的左边还有 $x$ 个 ...

随机推荐

  1. 一个简单的python爬虫,以豆瓣妹子“http://www.dbmeizi.com/category/2?p= ”为例

    本想抓取网易摄影上的图,但发现查看html源代码时找不到图片的url,但firebug却能定位得到.(不知道为什么???) 目标是抓取前50页的爆乳图,代码如下: import urllib2,url ...

  2. 层叠上下文(The stacking context)

    MDNThe stacking context 层叠上下文是HTML元素的三维概念,这些HTML元素在一条假想的相对于面向(电脑屏幕的)视窗或者网页的用户的z轴上延伸,HTML元素依据其自身属性按照优 ...

  3. KeyBord事件分发和接收简要过程代码示例

    step1:调用ViewRootImpl的内部类ImeInputStage的成员函数onProcess来判断输入法是否处于激活状态 final class ImeInputStage extends ...

  4. 学习node.js 第4篇 建立一个最小的web聊天系统

    我们生活在一个实时的世界里,有什么比聊天更加实时吗?那就让我们先写一个基于TCP 的聊天服务器吧,并且支持Telnet 连接.这很容易,而且能够完全用Node来编写.首先,我们需要在Node 中包含T ...

  5. Quartz.net打造信息抽取器

    由于最近的一个项目需要定时抽取特定XML信息,然后保存到数据库,最后通过WebApi把手机端要使用的方法给暴露出来,所以去研究了一下Quartz.net.由于项目很小,我没用到Autofac,Repo ...

  6. 【高清未加密】2015传智播客 最新21期c#asp.net 基础到就业班视频和源码

    [.NET]传智播客第[21]期就业班视频(高清无加密)本套2015年21期传智播客C#ASP.NET win10通用mvc+app开发视频教程附源码,是一套非常不错的asp.net自学视频教程,传智 ...

  7. 20135220谈愈敏Blog8_进程的切换和系统的一般执行过程

    进程的切换和系统的一般执行过程 谈愈敏 原创作品转载请注明出处 <Linux内核分析>MOOC课程 http://mooc.study.163.com/course/USTC-100002 ...

  8. 20135220谈愈敏Blog7_可执行程序的装载

    可执行程序的装载 谈愈敏 原创作品转载请注明出处 <Linux内核分析>MOOC课程 http://mooc.study.163.com/course/USTC-1000029000 一. ...

  9. 5332盛照宗 如何获取新技能+c语言学习调查

    如何获取新技能+c语言学习调查 你有什么技能比大多人(超过90%以上)更好? 如果问我有没有什么技能比大多数人,并且是90%的人好,我还真不敢说有,因为世界上有70亿人,要比63亿人做的好才行啊.我也 ...

  10. RxJava简介

    RxJava简介 本文为前段时间学习RxJava时留下的历史遗留笔记,仅作纪念,科学的大神教学帖子在这里-> 给 Android 开发者的 RxJava 详解 通过链式调用序列实现基于事件流的异 ...