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

41 21 21 00 10 2

output

NO

input

21 31 0-1 3

output

YES

题意:给你x,y,还有n条直线,问你在x到y的区域内部是否存在交点,不包括x,y上题解:贪心,我们知道在x,y上必然存在两个交点,所以我们贪心按照左边从小到大排序,如果右边不是递增的则存在交点

///1085422276
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
inline ll read()
{
    ll x=0,f=1;
    char ch=getchar();
    while(ch<‘0‘||ch>‘9‘)
    {
        if(ch==‘-‘)f=-1;
        ch=getchar();
    }
    while(ch>=‘0‘&&ch<=‘9‘)
    {
        x=x*10+ch-‘0‘;
        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=0;
   for(int i=1;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+1,G+kk+1,cmp);
   double now=-1,last=G[1].r;
   for(int i=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;
}

代码

				
时间: 2024-11-10 14:53:52

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

Codeforces Round #253 (Div. 2) A. Anton and Letters

题目很简单,只需要注意带空格的输入用getline即可 #include <iostream> #include <vector> #include <algorithm> #include <string> #include <set> using namespace std; int main(){ string str; getline(cin,str); set<char> a; for(int i= 1 ; i < s

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

Anton is playing a very interesting computer game, but now he is stuck at one of the levels. To pass to the next level he has to prepare npotions. Anton has a special kettle, that can prepare one potions in x seconds. Also, he knows spells of two typ

Codeforces Round #379 (Div. 2) D. Anton and Chess(模拟)

Anton likes to play chess. Also, he likes to do programming. That is why he decided to write the program that plays chess. However, he finds the game on 8 to 8 board to too simple, he uses an infinite one instead. The first task he faced is to check

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

B. Anton and currency you all know time limit per test 0.5 seconds memory limit per test 256 megabytes input standard input output standard output Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that

随笔—邀请赛前练— Codeforces Round #329 (Div. 2) 2Char

题意:给你多个字符串,只保留2及2个以内的字符,丢弃多余的字符串,问你最后留下的字符串最长能有多长? 思路: 1. 对每个字符串处理出  process[fir][sec]  只包含fir字符和sec字符 当前的最大长度.当然,超过2个字符的字符串自动跳过. 2. 注意合并 process[fir][sec].process[sec][fir].process[fir][0].process[sec][0] 3. 合并的过程还要注意特殊情况 process[fir][0] + process[s

Codeforces Round #329 (Div. 2) A.2Char 暴力

A. 2Char Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is that each of them uses at most two distinct letters. Andrew decided to send an article to the magazine, but as he hasn't written any article, h

Codeforces Round #379 (Div. 2) E. Anton and Tree

题意:给你一棵树, 每个点要么是黑色要么是白色, 有一种操作是将同一个颜色的连通块变成相反的颜色,问你最少变换几次, 整颗树变成一种颜色. 思路: 缩点, 加求树的直径, 答案为树的直径除二向上取整. 1 #include<bits/stdc++.h> 2 #define LL long long 3 #define mk make_pair 4 using namespace std; 5 6 const int N = 5e5 + 7; 7 const int inf = 0x3f3f3f

Codeforces Round #FF (Div. 2) D. DZY Loves Modification 贪心+优先队列

链接:http://codeforces.com/problemset/problem/447/D 题意:一个n*m的矩阵.能够进行k次操作,每次操作室对某一行或某一列的的数都减p,获得的得分是这一行或列原来的数字之和.求N次操作之后得到的最高得分是多少. 思路:首先分别统计每行和每列的数字和. 进行的k次操作中,有i次操作是对行进行操作,剩余k-i次操作是对列进行操作. 首先在操作中忽略每次操作中行对列的影响,然后计算列的时候,最后能够计算出,总共的影响是i*(k-i)*p. 找出对于每一个i

Codeforces Round #415 (Div. 2) B. Summer sell-off(贪心+结构体排序)

题目链接:http://codeforces.com/contest/810/problem/B 题意:给定天数和货物可以翻倍的天数,每天都有一定的货物量和顾客数,问怎么样货物才能卖得最多(前一天的货物不会留到下一天,每个顾客只能买一个货物). 简单的贪心问题,贪心策略是:如果两倍的货物量卖出去的更多,就选两倍的,否则就选一倍的. 那一天能卖出去的货物量:min(货物量,顾客数).然后根据结构体排序一下就ok了 1 #include <iostream> 2 #include <algo