bzoj。 1007: [HNOI2008]水平可见直线

1007: [HNOI2008]水平可见直线

Time Limit: 1 Sec   Memory Limit: 162 MB
Submit: 8043   Solved: 3060
[ Submit][ Status][ Discuss]

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

HINT

类半平面交的题。。。先极角排序,因为k给出了直接用k排序,然后根据斜率,画图看一看。。。

后序的形成的点如果在前序点的左边,就会把之前的线给覆盖掉。。。

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
const int maxn = 51550;
const double esp = 1e-9;
int n, pn,  top;
vector<int> ans;
struct Line {
    int k, b, id;
    bool operator < (const Line& l) const {
        return k < l.k || (k == l.k && b > l.b);
    }
    bool operator == (const Line& l) const {
        return k == l.k;
    }
}l[maxn], dq[maxn];

double get_x(const Line& l1, const Line& l2) {
    return (l2.b - l1.b) * 1.0/ (l1.k - l2.k);
}
void solve() {
    sort(l + 1, l + n + 1);
    n = int(unique(l + 1, l + n + 1) - l - 1);
    top = 1;
    for (int i = 1; i <= n; ++i) {
        while (top > 2 && (get_x(dq[top - 1], dq[top - 2]) > (get_x(dq[top - 1], l[i])) - esp))
            top--;
        dq[top++] = l[i];
    }
   
    for (int i = 1; i < top; ++i) {
        ans.push_back(dq[i].id);
    }
    sort(ans.begin(), ans.end());
    for (int i = 0; i < ans.size(); ++i) {
        cout << ans[i] << " ";
    }
    //cout << endl;
}

int main() {
    //freopen("in.txt", "r", stdin);
    cin >> n;
    int k, b;
    for (int i = 1; i <= n; ++i) {
        cin >> k >> b;
        l[i] = Line{k, b, i};
    }
    solve();
}



啊蠢了一晚上。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值