B. Anton and Lines
The teacher gave Anton a large geometry homework, but he didn ' t does it (as usual) as he participated in a regular round On Codeforces. In the task he is given a set Of n lines defined by the Equations y = k i • X + b i . It was necessary to determine whether there are at least one point of intersection of one of the these lines, that lays strictl Y inside the Strip Between x 1 < x 2. In other words, was it true that there Are1≤ I < j ≤ n and x ', y ', such that:
- y' = ki * x' + bi, that's, point (x', Y') belongs to the line number I;
- y' = kJ * x' + bJ, that's, point ( x', y') belongs to the line number J;
- x 1 < x' < x2, that's, point (x', y') lies inside the strip bounded b Y x1 < x2.
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) -the number of lines in the task given to Anton. The second line contains Integers x 1 and x 2 (-1 000 000≤ x Span class= "Lower-index" >1 < x 2≤1) defining the strip inside which you nee D to find a point of intersection of at least-lines.
The following n lines contain integers ki, bi ( - 1 000 000≤ Ki, bi ≤1)-the descriptions of the lines. It is guaranteed so all lines be pairwise distinct, that's, for any II i ≠ J it is true th At either Ki ≠ kJ, or bi ≠ b J.
Output
Print "Yes" (without quotes), if there is at least one intersection of the 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
Test Instructions : give you x, Y, and N lines, and ask you if there is an intersection within the X-to-y area, not including X, Y
problem: Greedy, we know there must be two intersections on X, y, so we greedy on the left from small to large sort, if the right is not incremented then there is an intersection
///1085422276#include <bits/stdc++.h>using namespacestd; typedefLong Longll;#defineMem (a) memset (A,0,sizeof (a))inline ll read () {ll x=0, f=1; CharCh=GetChar (); while(ch<'0'|| Ch>'9') { if(ch=='-') f=-1; CH=GetChar (); } while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; CH=GetChar (); } returnx*F;}//****************************************#defineMAXN 1000000+5#defineMoD 1000000007DoubleK[MAXN],B[MAXN];structss{Doublel; DoubleR; intindex;} G[MAXN];intCMP (ss S1,ss S2) {if(S1.L==S2.L)returns1.r<S2.R; Else returns1.l<S2.L;}intN;intMain () {n=read (); Doublex, y; scanf ("%LF%LF",&x,&y); intkk=0; for(intI=1; i<=n;i++) {scanf ("%LF%LF",&k[i],&B[i]); Doublexx=k[i]*x+B[i]; Doubleyy=k[i]*y+B[i]; g[++kk].l=xx; G[kk].r=yy; } sort (G+1, g+kk+1, CMP); Doublenow=-1, last=g[1].R; for(intI=2; i<=kk;i++){ if(g[i].r<Last ) {cout<<"YES"<<Endl; return 0; } Now=G[I].L; Last=G[I].R; } cout<<"NO"<<Endl; return 0;}
Code
Codeforces Round #329 (Div. 2) B. Anton and Lines greedy