Codeforces 593B 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 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.
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
2
1 3
1 0
0 2
YES
2
1 3
1 0
0 3
NO
In the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it.
Solution
两直线y1, y2交点横坐标在开区间(x1, x2)的充要条件:(y1(x1)-y2(x1))*(y1(x2)-y2(x2)) < 0
直线y对应二元组(y(x1), y(x2)),即直线y被x=x1, x=x2所截得的线段,将所有二元组按字典序排序只要判断是否有相邻两线段相交的情况即可。
Implementation
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL mod(1e9+); const int N(1e5+); int sign(LL x){
return x?x>?:-:;
} vector<pair<LL,LL>> seg; int main(){
ios::sync_with_stdio(false);
cin.tie(), cout.tie(); int n, x1, x2;
cin>>n>>x1>>x2;
LL k, b;
for(int i=; i<n; i++){
cin>>k>>b;
LL y1=k*x1+b, y2=k*x2+b;
seg.push_back({y1, y2});
} sort(seg.begin(), seg.end());
for(int i=; i<seg.size(); i++){
if(sign(seg[i].first-seg[i-].first)*sign(seg[i].second-seg[i-].second)<){
puts("YES");
return ;
}
}
puts("NO");
return ;
}
Codeforces 593B Anton and Lines的更多相关文章
- CF 593B Anton and Lines(水题)
题意是给你n条直线,和x1,x2;问 在x1,x2之间(不包括在x1,x2上) 存不存在任意两条线的交点. 说思路,其实很简单,因为给的直线的条数很多,所以无法暴力求每两条直线的交点,那么就求每条直线 ...
- 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 #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 ...
- Anton and Lines(思维)
Anton and Lines time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- Codeforces 734E. Anton and Tree 搜索
E. Anton and Tree time limit per test: 3 seconds memory limit per test :256 megabytes input:standard ...
- Codeforces 734D. Anton and Chess(模拟)
Anton likes to play chess. Also, he likes to do programming. That is why he decided to write the pro ...
- Codeforces 734F Anton and School(位运算)
[题目链接] http://codeforces.com/problemset/problem/734/F [题目大意] 给出数列b和数列c,求数列a,如果不存在则输出-1 [题解] 我们发现: bi ...
- [刷题]Codeforces 785D - Anton and School - 2
Description As you probably know, Anton goes to school. One of the school subjects that Anton studie ...
- Codeforces 785D - Anton and School - 2 - [范德蒙德恒等式][快速幂+逆元]
题目链接:https://codeforces.com/problemset/problem/785/D 题解: 首先很好想的,如果我们预处理出每个 "(" 的左边还有 $x$ 个 ...
随机推荐
- android studio 中的编码问题
在 Android studio 中直接创建项目和导入其他项目都会有一个文件编码设定的问题,在 android studio (version 1.2.0)中设置文件的编码,只需要两步: 1.打开Se ...
- HTML5和css3的总结三
继续总结H5的新东西 1>序列化与反序列化 序列化:其实就是一个json->string的过程 JSON.stringify(json); 反序列化:string->json的过程( ...
- 【转】【C#】ColorMatrix
ColorMatrix(色彩矩阵),是GDI+里用来调整图片色彩的矩阵. 什么是矩阵,说白了就是C#里的二维数组. 那么这个矩阵调整色彩的原理是什么,他是怎么来调整色彩的呢?这个要从线性代数里的矩阵相 ...
- bzoj roll题器(Py大法好)
此roll题器能实现非权限号跳过权限题及所有号跳过已切题 点击下载rar文件(py2) 点击下载rar文件(py3)
- 在matlab中实现遥感影像和shp文件的结合显示
clc;close all;clear; road=shaperead('boston_roads.shp'); %读取shape文件 figure, mapshow('boston.tif'); % ...
- Ubuntu 14.04 下安装google的浏览器——Chrome
小编用过好多浏览器,但最后还是选择Chrome, 因为这款浏览器确实做的不错,可是Ubuntu下自带的是火狐,因此小编在这里和大家分享一下如何在Ubuntu下安装chrome浏览器 工具/原料 安 ...
- IM架构(一)JSQMessagesViewController
JSQMessagesViewController 是 Jesse Squires 开发的一个消息界面的 UI 库.
- Quartz.NET syudy
Quartz.NET Quartz.NET是一个开源的作业调度框架,是OpenSymphony 的 Quartz API的.NET移植,它用C#写成,可用于winform和asp.net应用中.它 ...
- python&MongoDB爬取图书馆借阅记录(没有验证码)
题外话:这个爬虫本来是想用java完成然后发布在博客园里的,但是一直用java都失败了,最后看到别人用了python,然后自己就找别人问了问关键的知识点,发现连接那部分,python只用了19行!!! ...
- 让C#开发更简单,抽象增删改
相信经常做一些MS,CRM 项目的童鞋非常有体会,大部分时间都是在复制和粘贴,大部分项目框架都是建一个三层,首先是DAL建一些增删改查,然后呢是BLL业务层再建一些增删改查,然后UI层再调用增删改查, ...