1007: [HNOI2008]水平可见直线
Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 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
-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();
}