【HNOI2008】【BZOJ1007】水平可见直线

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

Source

弱化版半平面交
不能解释更多…(这个水题我竟然又没写过)

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define MAXN 50100
#define eps 1e-9
using namespace std;
int n,top;
bool vis[MAXN];
struct Vector
{
    double a,b;
    int id;
    bool operator <(const Vector& A)const
    {
        if (fabs(A.a-a)<eps)    return b<A.b;
        return a<A.a;
    }
}v[MAXN];
Vector sta[MAXN];
double Get_x(Vector A,Vector B)
{
    return (B.b-A.b)/(A.a-B.a);
}
int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;i++)  scanf("%lf%lf",&v[i].a,&v[i].b),v[i].id=i;
    sort(v+1,v+n+1);
    for (int i=1;i<=n;i++)
    {
        while (top)
        {
            if (fabs(sta[top].a-v[i].a)<eps)    {   top--;  continue;   }
            if (top>1&&Get_x(v[i],sta[top-1])<=Get_x(sta[top],sta[top-1]))  top--;
            else    break;
        }
        sta[++top]=v[i];
    }
    while (top) vis[sta[top--].id]=1;
    for (int i=1;i<=n;i++)
        if (vis[i]) printf("%d ",i);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值