[bzoj1007][HNOI2008][水平可见直线] (斜率不等式)
2024-10-13 10:13:50
Description
在xoy直角坐标平面上有n条直线L1,L2,...Ln,若在y值为正无穷大处往下看,能见到Li的某个子线段,则称Li为
可见的,否则Li为被覆盖的.
例如,对于直线:
L1:y=x; L2:y=-x; L3:y=0
则L1和L2是可见的,L3是被覆盖的.
给出n条直线,表示成y=Ax+B的形式(|A|,|B|<=500000),且n条直线两两不重合.求出所有可见的直线.
Input
第一行为N(0 < N < 50000),接下来的N行输入Ai,Bi
Output
从小到大输出可见直线的编号,两两中间用空格隔开,最后一个数字后面也必须有个空格
Sample Input
3
-1 0
1 0
0 0
-1 0
1 0
0 0
Sample Output
1 2
Solution
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define MAXN 50010
#define Eps 1e-18 using namespace std; struct Liyn{
int k, b, pos; void Push(int i) {scanf("%d%d", &k, &b); pos = i;} bool operator == (const Liyn &a)const {return k == a.k;} bool operator < (const Liyn &a)const {return k < a.k || (k == a.k && b > a.b);} double Cmp(const Liyn &a) {return double(a.b - b) / double(k - a.k);}
}L[MAXN], _pb[MAXN]; int n, top, ans[MAXN]; int main(){
scanf("%d", &n);
for(int i = ; i < n; i++)
L[i].Push(i);
sort(L, L + n);
n = unique(L, L + n) - L;
for(int i = ; i < n; i++){
while(top > && _pb[top - ].Cmp(_pb[top - ]) > L[i].Cmp(_pb[top - ]) - Eps)top--;
_pb[top++] = L[i];
}
for(int i = ; i < top; i++)
ans[i] = _pb[i].pos;
sort(ans, ans + top);
for(int i = ; i < top; i++)
printf("%d ", ans[i] + );
return ;
}
最新文章
- linux下安装apache与php;Apache+PHP+MySQL配置攻略
- 删除项目中的CocoaPods
- 缺陷管理系统mantisbt环境搭建
- 使用Guava来计算笛卡尔积
- 安装shopex注意事项
- 虚函数(virtual)为啥不能是static
- socket的accept函数解析
- m个苹果放入n个盘子问题
- .Net Core下使用WCF
- 学习Object.assign()
- Windows zip安装MySQL
- Ajax.html:35 [Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user&#39;s experience. For more help, check https://xhr.spec.whatwg.org
- Oracle EBS SLA 详解
- 程序员十大热门flag,有你的吗?
- [Kubernetes]深入解析Pod对象
- python安装多版本
- 关于Python课程的一些思考。
- 140 - The 12th Zhejiang Provincial Collegiate Programming Contest(浙江省赛2015)
- WIN10护眼色
- 禁止用键盘左右箭头,去切换PageControl页签