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

来源:互联网 发布:工程造价软件有什么 编辑:程序博客网 时间:2024/05/16 18:06

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-9using 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);}
0 0
原创粉丝点击