题意是给你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(水题)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. Codeforces 593B Anton and Lines

    LINK time limit per test 1 second memory limit per test 256 megabytes input standard input output st ...

  4. 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 ...

  5. Codeforces Round #404 (Div. 2) A - Anton and Polyhedrons 水题

    A - Anton and Polyhedrons 题目连接: http://codeforces.com/contest/785/problem/A Description Anton's favo ...

  6. Codeforces Round #379 (Div. 2) B. Anton and Digits 水题

    B. Anton and Digits 题目连接: http://codeforces.com/contest/734/problem/B Description Recently Anton fou ...

  7. CF#FF(255)-div1-C【水题,枚举】

    [吐槽]:本来没打算写这题的题解的,但惨不忍睹得WA了13次,想想还是记录一下吧.自己的“分类讨论能力”本来就很差. 刚开始第一眼扫过去以为是LIS,然后忽略了复杂度,果断TLE了,说起来也好惭愧,也 ...

  8. CF 277.5 A.SwapSort 水题

    //STL教你做人系列 #include<stdio.h> #include<iostream> #include<math.h> #include<algo ...

  9. CF 628B New Skateboard --- 水题

    CD 628B 题目大意:给定一个数字(<=3*10^5),判断其能被4整除的连续子串有多少个 解题思路:注意一个整除4的性质: 若bc能被4整除,则a1a2a3a4...anbc也一定能被4整 ...

随机推荐

  1. linux下vim的安装与配置(centos)

    1.vim的安装 #yum search vim   //查看vim相关软件信息 #yum install -y vim*  //在线安装vim 2.vim的配置 (1)~/.viminfo 在vim ...

  2. Docker环境中部署Prometheus及node-exporter监控主机资源

    前提条件 已部署docker 已部署grafana 需要开放 3000 9100 和 9090 端口 启动node-exporter docker run --name node-exporter - ...

  3. 14. GLIBCXX_3.4.9' not found - 解决办法

    在Linux中安装交叉编译器arm-linux-gcc 4.4.3,然后编译mini2440内核出错: /usr/lib/libstdc++.so.6: version GLIBCXX_3.4.9' ...

  4. 【leetocode】55. Jump Game

    You are given an integer array nums. You are initially positioned at the array's first index, and ea ...

  5. MediaPlayer详解

    [1]MediaPlayer 详细使用细则 [2]MediaPlayer使用详解_为新手准备 [3]MediaPlayer 概览

  6. C++中union相关

    前两天做阿里笔试遇到一个选择题题目大概是 #include <iostream> #include <stdlib.h> using namespace std; union ...

  7. 转 android design library提供的TabLayout的用法

    原文出处:http://chenfuduo.me/2015/07/30/TabLayout-of-design-support-library/ 在开发中,我们常常需要ViewPager结合Fragm ...

  8. C++ 类型转换(C风格的强制转换):

    转https://www.cnblogs.com/Allen-rg/p/6999360.html C++ 类型转换(C风格的强制转换): 在C++基本的数据类型中,可以分为四类:整型,浮点型,字符型, ...

  9. 【Linux】【Services】【VersionControl】Git基础概念及使用

    1. 简介 1.1. 版本控制工具: 本地版本控制系统: 集中化版本控制系统:CVS,SVN 分布式版本控制系统: BitKeeper,Git 1.2. 官方网站: https://git-scm.c ...

  10. hadoop Sort排序

    1 public int getPartition(IntWritable key,IntWritable value,int numPartitions){ 2 int Maxnumber = 12 ...