Codeforces Round #329 (Div. 2) B. Anton and Lines ([好题] 计算直线在区间是否有交点)
来源:互联网 发布:js 银行卡格式 编辑:程序博客网 时间:2024/04/29 03:32
题目链接
题意:给出n个条直线,然后在指定的区间(x1,x2)是否有直线的交点存在。
解法:一:闭区间,首先把区间略微调小。
二:计算直线在x1,x2上的交点y坐标,以及直线的id,然后按照y值,id值排序,最后判断第x1,x2左右两边的第i个点是不是同一直线的,如果不是,就存在交点。
#include<bits/stdc++.h>using namespace std;const int maxn=100011;const int inf=1<<27;const long long mod=751492854;#define LL long long#define P pair<int,int>#define X first#define Y second#define pb push_back#define cl(a,b) memset(a,b,sizeof(a));struct node{ double y; int id; bool operator<(const node &t) const { return y<t.y||(y==t.y&&id<t.id); }};vector<node> A,B;int main(){ int n;scanf("%d",&n); double k,b,x1,x2; node tmp; scanf("%lf%lf",&x1,&x2); if(x1>x2)swap(x1,x2); x1+=1e-8;///题目是闭区间,所以这里微调 x2-=1e-8; for(int i=0;i<n;i++){ scanf("%lf%lf",&k,&b); tmp.y=k*x1+b; tmp.id=i; A.pb(tmp); tmp.y=k*x2+b; B.pb(tmp); } sort(A.begin(),A.end()); sort(B.begin(),B.end()); for(int i=0;i<n;i++){ if(A[i].id!=B[i].id){ puts("YES");return 0; } } puts("NO"); return 0;}
0 0
- Codeforces Round #329 (Div. 2) B. Anton and Lines ([好题] 计算直线在区间是否有交点)
- 【Codeforces Round 329 (Div 2) B】【映射 排序 贪心】Anton and Lines 查看所有直线pair在[x1,x2]范围内是否有交点
- Codeforces Round #329 (Div. 2)B. Anton and Lines
- Codeforces Round #329 (Div. 2)B. Anton and Lines
- Codeforces Round #329 (Div. 2)B. Anton and Lines
- Codeforces Round #329 (Div. 2) 593B - Anton and Lines
- CodeForces - 593B Anton and Lines (数学方程&技巧) 判断直线是否相交
- Codeforces Round #404 (Div. 2) B. Anton and Classes
- B. Anton and currency you all know(Codeforces Round #288 (Div. 2))
- Codeforces Round #379 (Div. 2) B. Anton and Digits(简单贪心)
- Codeforces 593B Anton and Lines 【思维】
- codeforces 593B Anton and Lines
- Codeforces 593B Anton and Lines
- CodeForces 593B - Anton and Lines(思维)
- Codeforces Round #404 (Div. 2)(D)Anton and School
- Codeforces Round #379 (Div. 2) -- D. Anton and Chess (if else 的水题)
- Codeforces Round #288 (Div. 2) B. Anton and currency you all know
- Codeforces Round #288 (Div. 2) B. Anton and currency you all know
- 将.sql文件导入powerdesigner的实现方法详解
- JavaScript高级程序设计之DOM 扩展之选择符API第11.1讲
- Shell行操作:逐行读取,指定行输出,指定行删除等
- php自学提升进阶路线
- servlet生命周期
- Codeforces Round #329 (Div. 2) B. Anton and Lines ([好题] 计算直线在区间是否有交点)
- 测试基础篇之【按钮通用测试点】
- 约瑟夫问题 java 实现
- 对市场的看法
- Android学习路线指南
- android下拉刷新带自定义声音
- html结构
- php打印函数
- C#中的ref和out关键字