B. Anton and Lines
 

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
4
1 2
1 2
1 0
0 1
0 2
output
NO
input
2
1 3
1 0
-1 3
output
YES

题意:给你x,y,还有n条直线,问你在x到y的区域内部是否存在交点,不包括x,y上
题解:贪心,我们知道在x,y上必然存在两个交点,所以我们贪心按照左边从小到大排序,如果右边不是递增的则存在交点
///
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
//****************************************
#define maxn 1000000+5
#define mod 1000000007 double k[maxn],b[maxn]; struct ss{ double l;
double r;
int index;
}G[maxn];
int cmp(ss s1,ss s2){
if(s1.l==s2.l)return s1.r<s2.r;
else return s1.l<s2.l;
}
int n;
int main(){ n=read();
double x,y;
scanf("%lf%lf",&x,&y);
int kk=;
for(int i=;i<=n;i++){
scanf("%lf%lf",&k[i],&b[i]);
double xx=k[i]*x+b[i];
double yy=k[i]*y+b[i];
G[++kk].l=xx;G[kk].r=yy;
}
sort(G+,G+kk+,cmp);
double now=-,last=G[].r;
for(int i=;i<=kk;i++){ if(G[i].r<last){
cout<<"YES"<<endl;
return ; }
now=G[i].l;
last=G[i].r;
}
cout<<"NO"<<endl;
return ;
}

代码


Codeforces Round #329 (Div. 2)B. Anton and Lines 贪心的更多相关文章

  1. 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 ...

  2. Codeforces Round #324 (Div. 2) E. Anton and Ira 贪心

    E. Anton and Ira Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/probl ...

  3. 贪心 Codeforces Round #288 (Div. 2) B. Anton and currency you all know

    题目传送门 /* 题意:从前面找一个数字和末尾数字调换使得变成偶数且为最大 贪心:考虑两种情况:1. 有偶数且比末尾数字大(flag标记):2. 有偶数但都比末尾数字小(x位置标记) 仿照别人写的,再 ...

  4. Codeforces Round #297 (Div. 2)C. Ilya and Sticks 贪心

    Codeforces Round #297 (Div. 2)C. Ilya and Sticks Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx  ...

  5. Codeforces Round #329 (Div. 2)

    推迟了15分钟开始,B卡住不会,最后弃疗,rating只涨一分...   水(暴力枚举) A - 2Char /******************************************** ...

  6. Codeforces Round #404 (Div. 2) D. Anton and School - 2 数学

    D. Anton and School - 2 题目连接: http://codeforces.com/contest/785/problem/D Description As you probabl ...

  7. Codeforces Round #379 (Div. 2) E. Anton and Tree 缩点 直径

    E. Anton and Tree 题目连接: http://codeforces.com/contest/734/problem/E Description Anton is growing a t ...

  8. Codeforces Round #379 (Div. 2) D. Anton and Chess 水题

    D. Anton and Chess 题目连接: http://codeforces.com/contest/734/problem/D Description Anton likes to play ...

  9. Codeforces Round #379 (Div. 2) C. Anton and Making Potions 枚举+二分

    C. Anton and Making Potions 题目连接: http://codeforces.com/contest/734/problem/C Description Anton is p ...

随机推荐

  1. java多线程(线程通信-等待换新机制-代码优化)

    等待唤醒机制涉及方法: wait():让线程处于冻结状态,被wait的线程会被存储到线程池中. noticfy():唤醒同一个线程池中一个线程(任意也可能是当前wait的线程) notifyAll() ...

  2. java读取03、07版EXCEL

    03版excel,需要用到jxl.jar这个jar包 package test.poi; import java.io.File; import java.io.IOException; import ...

  3. MFC_2.5 选项卡控件的使用

    选项卡控件的使用 1.新建默认MFC文件. 2.资源-添加Dialog-添加类.(假设生成3个,Dialog1Dialog2Dialog3) 3.类向导,添加类,点小三角形,添加MFC类.添加CTab ...

  4. cookie domain path 跨域

    1.domain表示的是cookie所在的域,默认为请求的地址,如网址为www.jb51.net/test/test.aspx,那么domain默认为www.jb51.net.而跨域访问,如域A为t1 ...

  5. HDU - 2044 - 一只小蜜蜂...(dp)

    题意: 如题 思路: 仔细观察图 1-4和3-6其实是一样的答案,那么所有的方案都可以相减,意思为全部转化为从1开始 剩下的就是观察规律,仔细观察5号,能到5号蜂房的只有3和4,3和4到5号蜂房只有一 ...

  6. [Algorithm] 11. Linked List Cycle

    Description Given a linked list, determine if it has a cycle in it. To represent a cycle in the give ...

  7. Linux:Apache改静态网页、个人用户主页、虚拟网站主机、Apache访问控制

    Apache改静态网页  1.概述: Apache是web服务器(静态解析,如HTML),tomcat是java应用服务器(动态解析,如JSP.PHP) Tomcat只是一个servlet(jsp也翻 ...

  8. python实现定时发送qq消息

    因为生活中老是忘记各种事情,刚好又在学python,便突发奇想通过python实现提醒任务的功能(尽管TIM有定时功能),也可定时给好友.群.讨论组发送qq消息.其工作流程是:访问数据库提取最近计划— ...

  9. SQL Server 机考,用T-SQL编写 简单实例

    使用T-SQL实现以下要求: 要求如下: 1,添加数据库:MySchool 2,添加学生基础表:Student 3,添加学生成绩表:ScoreInfo 4,两张表结构分别如下 Student表结构:( ...

  10. MessageFormat理解,MessageFormat.format(Object obj)方法

    MessageFormat.format(Object obj)方法主要用途为拼接message信息 用法: Object[] testArgs = {new String("张三" ...