您的位置:首页 > 其它

【BZOJ1007】[HNOI2008]水平可见直线【半平面交】

2016-05-18 15:32 453 查看
【题目链接】

学习一发计算几何基础。

/* Telekinetic Forest Guard */
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;

typedef double DB;

const int maxn = 50005;
const DB eps = 1e-6;

struct _line {
DB k, b;
int id;
} l[maxn];

int n, sta[maxn], top;

inline bool cmp(_line x, _line y) {
return fabs(x.k - y.k) < eps ? x.b < y.b : x.k < y.k;
}

inline bool cmp2(int x, int y) {
return l[x].id < l[y].id;
}

inline DB cosp(_line x, _line y) {
return (x.b - y.b) / (y.k - x.k);
}

inline void insert(int id) {
while(top) {
if(fabs(l[sta[top]].k - l[id].k) < eps) top--;
else if(top > 1 && cosp(l[id], l[sta[top - 1]]) <= cosp(l[sta[top]], l[sta[top - 1]])) top--;
else break;
}
sta[++top] = id;
}

int main() {
scanf("%d", &n);
for(int i = 1; i <= n; i++) scanf("%lf%lf", &l[i].k, &l[i].b), l[i].id = i;

sort(l + 1, l + 1 + n, cmp);

top = 0;
for(int i = 1; i <= n; i++) insert(i);
sort(sta + 1, sta + 1 + top, cmp2);
for(int i = 1; i <= top; i++) printf("%d ", l[sta[i]].id);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: