Codeforces Round #329 (Div. 2)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.
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 ki, bi ( - 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.
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).
4
1 2
1 2
1 0
0 1
0 2
NO
2
1 3
1 0
-1 3
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 贪心的更多相关文章
- 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 ...
- 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 ...
- 贪心 Codeforces Round #288 (Div. 2) B. Anton and currency you all know
题目传送门 /* 题意:从前面找一个数字和末尾数字调换使得变成偶数且为最大 贪心:考虑两种情况:1. 有偶数且比末尾数字大(flag标记):2. 有偶数但都比末尾数字小(x位置标记) 仿照别人写的,再 ...
- 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 ...
- Codeforces Round #329 (Div. 2)
推迟了15分钟开始,B卡住不会,最后弃疗,rating只涨一分... 水(暴力枚举) A - 2Char /******************************************** ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- Detectron-MaskRCnn:Mask判别和获取前向Mask的标签
对于FCN-SceneParse网络,最后卷积生成N个类别的maps,每个Map都得到图像所有点的单类概率.MaskRCNN的结构与FCN不相同. 参考三个文章: Detectron总结1:Blob的 ...
- 隐藏win10任务栏输入法M图标
在任务栏右键=>任务栏设置=>打开或关闭系统图标=>(关闭)输入指示
- R语言学习 - 线图绘制
线图是反映趋势变化的一种方式,其输入数据一般也是一个矩阵. 单线图 假设有这么一个矩阵,第一列为转录起始位点及其上下游5 kb的区域,第二列为H3K27ac修饰在这些区域的丰度,想绘制一张线图展示. ...
- Microsoft Access Engine
在64位Win7操作系统中安装Microsoft Access Engine的解决方案 原创 2014年01月06日 19:33:56 44847 现在的Win7系统中安装的一般都是32位的Offic ...
- Python之实例属性和类属性
参考原文 廖雪峰Python 实例属性和类属性 在前面已经说过由于Python是动态语言,可以根据类的实例绑定任何的属性. 给实例绑定属性的方法是通过实例变量,或者self变量绑定的: class S ...
- case when里的like功能 ////// 截取(substr)
case when里的like功能 假如要用到case when又要用到like这样的功能,即如果字符串包含‘语文’就怎么怎么样,包含‘数学’就怎么怎么样,包含‘英语’就怎么怎么样,like是用于wh ...
- Bookshelf 2(poj3628,01背包,dp递推)
题目链接:Bookshelf 2(点击进入) 题目解读: 给n头牛,给出每个牛的高度h[i],给出一个书架的高度b(所有牛的高度相加>书架高度b),现在把一些牛叠起来(每头牛只能用一次,但不同的 ...
- 洛谷——P3871 [TJOI2010]中位数
P3871 [TJOI2010]中位数 一眼秒掉,这不是splay水题吗,套模板 #include<bits/stdc++.h> #define IL inline #define N 1 ...
- gulp-file-include 合并 html 文件
gulp-file-include 是 gulp 插件,它提供了一个 include 方法让我们可以像后端模板那样把公共部分的页面导入进来. 安装依赖包(包括了 gulp-file-include 和 ...
- shoppping collection
personal shopping collections shop Table of Contents 1. phone network 2. band share 3. Motorcycle He ...