cf B. Anton and Lines (STL)

来源:互联网 发布:vb net入门教程pdf 编辑:程序博客网 时间:2024/04/29 10:45


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

Sample test(s)
input
41 21 21 00 10 2
output
NO
input
21 31 0-1 3
output
YES
input
21 31 00 2
output
YES
input
21 31 00 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.



#include<bits/stdc++.h>using namespace std;typedef long long ll;multiset<ll>ss;multiset<ll>::iterator it;struct node{ll l;ll r;} a[100100];bool cmp(node x,node y){if(x.l>y.l) return true;else if(x.l==y.l && x.r>y.r) return true;return false;}int main(){ ios::sync_with_stdio(false); int i,j,kk;ll n,k,b,t;ll x1,x2;cin>>n>>x1>>x2;kk=0;for(i=0;i<n;i++) {cin>>k>>b;a[i].l=k*x1+b;a[i].r=k*x2+b;ss.insert(a[i].r);}sort(a,a+n,cmp);for(i=0;i<n;i++) {t=a[i].r;it=ss.upper_bound(t);if(it!=ss.end()) break;ss.erase(ss.lower_bound(t));      // erase()不能删除一个num。。而是删除所有的值为num的 }if(i==n) cout<<"NO"<<endl;else cout<<"YES"<<endl;return 0;}




wc

#include <bits/stdc++.h>using namespace std;typedef long long LL;typedef unsigned long long ULL;const int N=100005;int INF=0x3f3f3f3f;LL mod=1e9+7;LL k[N],b[N],y11[N],y22[N];int a[N],c[N];bool cmp1(int p1,int p2){    if(y11[p1]==y11[p2]){        return y22[p1]<y22[p2];    }    return y11[p1]<y11[p2];}bool cmp2(int p1,int p2){    if(y22[p1]==y22[p2]){        return y11[p1]<y11[p2];    }    return y22[p1]<y22[p2];}int main(){    int n,x1,x2;    scanf("%d%d%d",&n,&x1,&x2);    for(int i=0;i<n;i++){        a[i]=c[i]=i;        scanf("%I64d%I64d",&k[i],&b[i]);        y11[i]=k[i]*x1+b[i];        y22[i]=k[i]*x2+b[i];    }    sort(a,a+n,cmp1);    sort(c,c+n,cmp2);    int ok=1;    for(int i=0;i<n;i++){        if(a[i]!=c[i]){            ok=0;            break;        }    }    puts(ok?"NO":"YES");    return 0;}




0 0
原创粉丝点击