CF 593B Anton and Lines(水题)

题意是给你n条直线,和x1,x2;问 在x1,x2之间(不包括在x1,x2上)
存不存在任意两条线的交点。
说思路,其实很简单,因为给的直线的条数很多,所以无法暴力求每两条直线的交点,那么就求每条直线与x1,x2的交点,
那么直线1和x1的交点y1与x2的交点y3,直线2与x1的交点y2与x2的交点y4,如果y1>y2,y3>y4,那么画个图就知道肯定不会有交点,反之如果y1>y2,y3<y4,则有交点。
那么求出交点排序,按与x1交点升序排,如果相同的话按与x2交点降序排(此时交点在x1上不合要求)。
那么前一项和后一项比,如果后一项与x2的交点大于前一项说明有交点存在,直接跳出。
这个代码不写注释,(很好理解)
1 #include<stdio.h>
2 #include<algorithm>
3 #include<iostream>
4 #include<stdlib.h>
5 #include<string.h>
6 #include<math.h>
7 int f(const void*p,const void*q);
8 using namespace std;
9 typedef struct pp
10 {
11 double x1;
12 double x2;
13 double t;
14 double p;
15 } ss;
16 ss a[100005];
17 int main(void)
18 {
19 int n,i,j,k,p,q;
20 double x1,x2,y1,y2;
21 while(scanf("%d",&n)!=EOF)
22 {
23 scanf("%lf %lf",&x1,&x2);
24 for(i=0; i<n; i++)
25 {
26 scanf("%lf %lf",&a[i].x1,&a[i].x2);
27 a[i].t=a[i].x1*x1+a[i].x2;
28 a[i].p=a[i].x1*x2+a[i].x2;
29
30 }
31 qsort(a,n,sizeof(ss),f);
32 int flag=0;
33 for(i=1; i<n; i++)
34 {
35 if(a[i].p<a[i-1].p)
36 {flag=1;
37 break;
38 }
39 }
40 if(flag)
41 {
42 printf("YES\n");
43 }
44 else printf("NO\n");
45
46
47
48 }
49
50
51 return 0;
52
53
54
55 }
56
57 int f(const void*p,const void*q)
58 {
59 ss*ww=(ss*)p;
60 ss*ee=(ss*)q;
61 if(ww->t==ee->t)
62 {
63 return ww->p>ee->p?1:-1;
64 }
65 else return ww->t>ee->t?1:-1;
66 }
CF 593B Anton and Lines(水题)的更多相关文章
- 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) A. Anton and Danik 水题
A. Anton and Danik 题目连接: http://codeforces.com/contest/734/problem/A Description Anton likes to play ...
- Codeforces 593B Anton and Lines
LINK time limit per test 1 second memory limit per test 256 megabytes input standard input output st ...
- Codeforces Round #404 (Div. 2) B. Anton and Classes 水题
B. Anton and Classes 题目连接: http://codeforces.com/contest/785/problem/B Description Anton likes to pl ...
- Codeforces Round #404 (Div. 2) A - Anton and Polyhedrons 水题
A - Anton and Polyhedrons 题目连接: http://codeforces.com/contest/785/problem/A Description Anton's favo ...
- Codeforces Round #379 (Div. 2) B. Anton and Digits 水题
B. Anton and Digits 题目连接: http://codeforces.com/contest/734/problem/B Description Recently Anton fou ...
- CF#FF(255)-div1-C【水题,枚举】
[吐槽]:本来没打算写这题的题解的,但惨不忍睹得WA了13次,想想还是记录一下吧.自己的“分类讨论能力”本来就很差. 刚开始第一眼扫过去以为是LIS,然后忽略了复杂度,果断TLE了,说起来也好惭愧,也 ...
- CF 277.5 A.SwapSort 水题
//STL教你做人系列 #include<stdio.h> #include<iostream> #include<math.h> #include<algo ...
- CF 628B New Skateboard --- 水题
CD 628B 题目大意:给定一个数字(<=3*10^5),判断其能被4整除的连续子串有多少个 解题思路:注意一个整除4的性质: 若bc能被4整除,则a1a2a3a4...anbc也一定能被4整 ...
随机推荐
- 以DevExpress开发的WinFrom程序的多语言功能的实现
以DevExpress开发的WinFrom程序的多语言功能的实现 写在前面: 多语言切换功能在Winform程序中是经常遇到的需求,尤其是需要给国外客户使用的情况下,多语言功能是必不可少的.前一段时间 ...
- UE4之Slate:App默认窗口的创建流程
UE4版本:4.24.3源码编译 Windows10 + VS2019开发环境 在先前分享的基础上,现在来梳理下App启动时默认窗口的创建流程,以及相关的类.对象之间的抽象层级: 纯C++工程配置 S ...
- django中的filter(), all(), get()
1. 类名.objects中的get(), filter(), all() 的区别 结论: (1)all()返回的是QuerySet对象,程序并没有真的在数据库中执行SQL语句查询数据,但支持迭代,使 ...
- collection映射
讲了manyToOne和oneToMany,下面来看看get方法.在之前已经说过,如果是映射单对象,直接使用association来映射.而如果关系 是一个集合,则需要使用collection来描述. ...
- Linux学习 - 环境变量配置文件
一.环境变量配置文件的作用 /etc/profile /etc/profile.d/*.sh ~/.bash_profile ~/.bashrc /etc/bashrc 1 /etc/profile的 ...
- OSGi系列 - 使用Eclipse查看Bundle源码
使用Eclipse开发OSGi Bundle时,会发现有很多现成的Bundle可以用.但如何使用这些Bundle呢?除了上网搜索查资料外,阅读这些Bundle的源码也是一个很好的方法. 本文以org. ...
- Dubbo服务限流
为了防止某个消费者的QPS或是所有消费者的QPS总和突然飙升而导致的重要服务的失效,系统可以对访问流量进行控制,这种对集群的保护措施称为服务限流. Dubbo中能够实现服务限流的方式较多,可以划分为两 ...
- Spring Batch(8) -- Listeners
September 29, 2020 by Ayoosh Sharma In this article, we will take a deep dive into different types o ...
- grep命令输出显示高亮字
grep命令执行后,终端上输出显示颜色可以加"--color=auto"的参数. 另外的两个办法是: 1.设置环境变量: export GREP_OPTIONS="--c ...
- 一种基于Java Swing/HTML/MySQL的汽车租赁系统
该项目是一个Java的课程作业(大二),主要运用Java.Swing.HTML.MySQL,实现基本的租车逻辑.界面可视化.信息导出.数据存储等功能.实现管理员.用户两种角色登录,并结合Java开发中 ...