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整 ...
随机推荐
- 论文解读(SDNE)《Structural Deep Network Embedding》
论文题目:<Structural Deep Network Embedding>发表时间: KDD 2016 论文作者: Aditya Grover;Aditya Grover; Ju ...
- 第二个基础框架 — spring — xml版,没用注解 — 更新完毕
1.什么是spring? 老规矩:百度百科一手 这上面说得太多了,我来提炼一下: spring就是一个轻量级的控制反转( IOC ) 和 面向切面编程( AOP ) 的容量框架.总的来说:本质就是对j ...
- LeetCode子矩形查询
LeetCode 子矩形查询 题目描述 请你实现一个类SubrectangleQueries,它的构造函数的参数是一个rows * cols的矩形(这里用整数矩阵表示),并支持以下两种操作: upda ...
- Java偏向锁浅析
偏向锁的定义 顾名思义,偏向锁会偏向第一个访问锁的线程. 如果在接下来的运行过程中,该锁没有被其他线程访问,这持有偏向锁的线程将永远不需要同步 如果在运行过程中,遇到了其他线程抢占锁,则持有偏向锁的线 ...
- c++ cmake及包管理工具conan简单入门
cmake是一个跨平台的c/c++工程管理工具,可以通过cmake轻松管理我们的项目 conan是一个包管理工具,能够自动帮助我们下载及管理依赖,可以配合cmake使用 这是一个入门教程,想深入了解的 ...
- 【leetcode】917. Reverse Only Letters(双指针)
Given a string s, reverse the string according to the following rules: All the characters that are n ...
- 【STM32】基于正点原子『探索者』开发板的烧录
项目需要一个功能,开发板范例正好有,就买了一块,不过还是有点贵 我手边没有J-Link 用的都是串口烧录 烧录时,先打开右上的开关 如果是仿真器烧录,它无法供电,需要接12V适配器或是杜邦线供电 然后 ...
- Playing with Destructors in C++
Predict the output of the below code snippet. 1 #include <iostream> 2 using namespace std; 3 4 ...
- Linux:spool命令
格式调整有以下参数: set echo on/off--是否显示脚本中的需要执行的命令 set feedback on/off--是否显示 select 结果之后返回多少行的提示 set linesi ...
- 【Linux】【Shell】【Basic】数组
1. 数组: 变量:存储单个元素的内存空间: 数组:存储多个元素的连续的内存空间: 数组名:整个数组只有一个名字: 数组 ...