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整 ...
随机推荐
- Hadoop入门 概念
Hadoop是分布式系统基础架构,通常指Hadoop生态圈 主要解决 1.海量数据的存储 2.海量数据的分析计算 优势 高可靠性:Hadoop底层维护多个数据副本,即使Hadoop某个计算元素或存储出 ...
- abide, able, abnormal
abide 近/反义词:1. 忍受: bear, endure, put up with, stand, tolerate2. 遵守(abide by): accept, comply, confor ...
- adjective
形容词用来描述名词或代词:副词用来描述剩下的(动词.形容词.副词和整句).adverb: to word. Adjectives are used almost exclusively to modi ...
- flink03-----1.Task的划分 2.共享资源槽 3.flink的容错
1. Task的划分 在flink中,划分task的依据是发生shuffle(也叫redistrubute),或者是并行度发生变化 1. wordcount为例 package cn._51doit ...
- 循环队列/顺序队列(C++)
队列(queue)是一种限定存取位置的线性变.他允许在表的一端插入,在另一端删除.这个和计算机调度策略中的先来先服务FCFS(First Come/First Served)是一样的.队列中可以插入的 ...
- centos7.4 64位安装 redis-4.0.0
1. 下载 redis 包 链接:https://pan.baidu.com/s/1g1UE_GTreXoD9uOXB7G3HA 提取码:ug8p 2. 安装gcc.ruby .rubygems等环 ...
- Spring boot 数据源配置。
配置文件 : spring boot 配置文件 有两种形式 ,一种是properties文件.一种是yml文件.案列使用properties文件. 数据源的默认配置 : spring boot 约定 ...
- 6、Redis五大数据类型---列表(List)
一.列表(List)简介 单键多值:Redis 列表是简单的字符串列表,按照插入顺序排序.你可以添加一个元素到列表的头部(左边)或者尾部(右边). 它的底层实际是个双向链表,对两端的操作性能很高,通过 ...
- Jenkins插件维护
目录 一.简介 二.插件安装 在线安装插件 上传安装插件 从其它jenkins复制插件 配置插件加速器 一.简介 除了在线安装,还可以官网插件下载地址中进行下载安装,如果访问缓慢可以用清华镜像站. 二 ...
- 磁盘管理LVM
目录 一.简介 二.操作 环境简介 操作 一.简介 LVM全称为Logical Volume Management,它是Linux环境下对磁盘分区进行管理的一种机制,它可以将多个硬盘合成一个资源池,然 ...