您的位置:首页 > 其它

[bzoj1007][HNOI2008][水平可见直线] (斜率不等式)

2016-12-31 22:34 239 查看

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

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 = 0; i < n; i++)
L[i].Push(i);
sort(L, L + n);
n = unique(L, L + n) - L;
for(int i = 0; i < n; i++){
while(top > 1 && _pb[top - 1].Cmp(_pb[top - 2]) > L[i].Cmp(_pb[top - 1]) - Eps)top--;
_pb[top++] = L[i];
}
for(int i = 0; i < top; i++)
ans[i] = _pb[i].pos;
sort(ans, ans + top);
for(int i = 0; i < top; i++)
printf("%d ", ans[i] + 1);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: