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

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

题解:如果两个直线在x1--x2间有交点,必然对于直线A的y1,y2,包含直线B的y1,y2;只要知道这就可以了,求出每个点的y1,y2排序判断就好:

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int INF=0x3f3f3f3f;
#define mem(x,y) memset(x,y,sizeof(x))
#define SI(x) scanf("%d",&x)
#define PI(x) printf("%d",x)
#define P_ printf(" ")
typedef __int64 LL;
const int MAXN=;
struct Node{
LL l,r;
bool operator < (const Node b) const{
if(l!=b.l)return l<b.l;
else return r<b.r;
}
};
Node dt[MAXN];
int main(){
int N,x1,x2;
LL k,b;
while(~scanf("%d",&N)){
scanf("%d%d",&x1,&x2);
for(int i=;i<N;i++){
scanf("%I64d%I64d",&k,&b);
dt[i].l=k*x1+b;dt[i].r=k*x2+b;
}
sort(dt,dt+N);
int flot=,k=;
for(int i=;i<N;i++){
if(dt[i].l>dt[k].l&&dt[i].r<dt[k].r)flot=;
while(dt[i].r>dt[k].r)k++;
}
if(flot)puts("YES");
else puts("NO");
}
return ;
}

暴力必然超时:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int INF=0x3f3f3f3f;
#define mem(x,y) memset(x,y,sizeof(x))
#define SI(x) scanf("%d",&x)
#define PI(x) printf("%d",x)
#define P_ printf(" ")
typedef __int64 LL;
double x1,x2;
const int MAXN=;
struct Node{
int k,b;
};
Node dt[MAXN];
bool js(Node x,Node y){
if(x.k==y.k)return false;
double temp=1.0*(y.b-x.b)/(x.k-y.k);
// printf("%lf\n",temp);
if(temp>x1&&temp<x2)return true;
else return false;
}
int main(){
int n;
while(~scanf("%d",&n)){
scanf("%lf%lf",&x1,&x2);
for(int i=;i<n;i++){
scanf("%d%d",&dt[i].k,&dt[i].b);
}
int flot=; for(int i=;i<n;i++){
if(flot)break;
for(int j=i+;j<n;j++){
if(js(dt[i],dt[j]))flot=;
if(flot)break;
}
}
if(flot)puts("YES");
else puts("NO");
}
}

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

  3. Codeforces 593B Anton and Lines

    LINK time limit per test 1 second memory limit per test 256 megabytes input standard input output st ...

  4. hud 5124 lines(思维 + 离散化)

    http://acm.hdu.edu.cn/showproblem.php?pid=5124 lines   Problem Description: John has several lines. ...

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

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

  6. Codeforces Round #329 (Div. 2)

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

  7. UVA1471-Defense Lines(思维+STL)

    Problem UVA1471-Defense Lines Accept: 297  Submit: 2776Time Limit: 9000 mSec Problem Description Aft ...

  8. Anton and Chess(模拟+思维)

    http://codeforces.com/group/1EzrFFyOc0/contest/734/problem/D 题意:就是给你一个很大的棋盘,给你一个白棋的位置还有n个黑棋的位置,问你黑棋能 ...

  9. Codeforces Round #381 (Div. 2)C. Alyona and mex(思维)

    C. Alyona and mex Problem Description: Alyona's mother wants to present an array of n non-negative i ...

随机推荐

  1. 一些常用运行命令和CMD命令

    运行命令 1. 进入服务页面的命令: services.msc 2. 远程连接命令:mstsc.exe 3. 配置电脑启动项 msconfig 4. 计算器 calc.exe 5. 设定关机时间(se ...

  2. 【技术文档】《算法设计与分析导论》R.C.T.Lee等·第5章 树搜索策略

    计算机中许多问题的解空间可以用一棵树来表示,最优解就在树中的一个分支上,因此,我们在解这类问题时可以采用树搜索策略,最经典的问题包括0/1背包问题.旅行商问题.哈密顿回路问题,还有8数码问题(就是我们 ...

  3. VS2012+SQL2008+ODBC编程,第一篇博客,写的不好忘各位大神指点一二~

    近期写一个数据库的课程设计,用的是C++ MFC .最開始用的是ADO技术,可是苦于网上大部分的教程都是VC6.0的,对着教程敲了4,5遍还是执行不成功.我用的IDE是VS2012,毕竟VC6.0和V ...

  4. Qemu之Network Device全虚拟方案三: I/O虚拟化

    前面两文主要对前端网络流的数据路径和虚拟网卡的创建进行了说明,这些能够看做是Guest OS网络数据包收发的准备工作,那么网络数据包是怎样在Guest OS中进进出出的呢,本文就是重点讲述Guest ...

  5. wpf实现IE菜单栏自动隐藏效果

    IE菜单栏默认为隐藏状态,按下键盘Alt键后显示,菜单失去焦点则自动隐藏.下面说说WPF中如何实现这样的效果. 第一步:Menu默认设置为隐藏(Visibility="Collapsed&q ...

  6. kaggle之电影评论文本情感分类

    电影文本情感分类 Github地址 Kaggle地址 这个任务主要是对电影评论文本进行情感分类,主要分为正面评论和负面评论,所以是一个二分类问题,二分类模型我们可以选取一些常见的模型比如贝叶斯.逻辑回 ...

  7. 动态根据checkbox 增加Dom

    <%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" ...

  8. 自学HTML的几个例子

    此处不赘述HTML中不同标签的用法仅仅给出自己学习时写的一些自娱自乐的例子,具体标签用法请参考W3C(http://www.w3school.com.cn/),毕竟这个才是最靠谱的,请不要相信任何二道 ...

  9. .NET Framework 4.0-RequestValidationMode

    1.WebForm 先看如下 web.config 的代码: <system.web> <compilation debug="true" targetFrame ...

  10. OCMOCM

    14年,OCM考试费12000 15年,考试费19800 对于我来说,1,2年之后是否换工作还是个未知数 在本单位考这个貌似没什么用处,工资也不会突然就涨很多 跳槽的话,专门做数据库感觉压力还挺大 年 ...