【BZOJ】 1007: [HNOI2008]水平可见直线(凸壳)

http://www.lydsy.com/JudgeOnline/problem.php?id=1007

一开始我贪心的写了下,当然全wa了。。

这题看了题解感觉很简单。

首先什么情况才能看到呢?

wobuzhidao。

我画图才看出门道的。。

当前直线与相对他斜率次大和次次大的2条直线时,如果与次大的(或者次次大)的交点在次大与次次大的交点左边,那么次大的直线一定被覆盖掉了!

画图自己看!(其实也就是这三个点形成一个凸包,然后上凸包的边所在直线一定看得到,下凸包一定被覆盖!)

所以我们用一个栈来维护这3者的关系

#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << #x << " = " << x << endl
#define printarr(a, n, m) rep(aaa, n) { rep(bbb, m) cout << a[aaa][bbb]; cout << endl; }
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; }

const int N=50005;
struct Line { double a, b; int id; }l[N];
const bool cmp(const Line &a, const Line &b) { return (abs(a.a-b.a)<=1e-10) ? a.b<b.b : a.a<b.a; }
int n, vis[N], top, st[N];

inline double crossx(const int &x, const int &y) { return (double)(l[x].b-l[y].b)/(l[y].a-l[x].a); }
inline void insert(const int &x) {
	while(top) {
		if(abs(l[st[top]].a-l[x].a)<=1e-10) --top;
		else if(top>1 && crossx(x, st[top])<=crossx(st[top], st[top-1])) --top;
		else break;
	}
	st[++top]=x;
}
int main() {
	read(n);
	for1(i, 1, n) { read(l[i].a); read(l[i].b); l[i].id=i; }
	sort(l+1, l+1+n, cmp);
	for1(i, 1, n) insert(i);
	for1(i, 1, top) vis[l[st[i]].id]=1;
	for1(i, 1, n) if(vis[i]) printf("%d ", i);
	return 0;
}

 

 

 


 

 

 

Description

Input

第一行为N(0 < N < 50000),接下来的N行输入Ai,Bi

Output

从小到大输出可见直线的编号,两两中间用空格隔开,最后一个数字后面也必须有个空格

Sample Input

3
-1 0
1 0
0 0

Sample Output

1 2

HINT

Source

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值