zoukankan      html  css  js  c++  java
  • BZOJ 1007: [HNOI2008]水平可见直线

    BZOJ 1007: [HNOI2008]水平可见直线

    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

    Solution

    一眼题,用栈维护一个上凸包即可。注意:去重别相信题目。

    Code

    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<queue>
    #include<algorithm>
    #define fo(i,a,b) for(int i=a;i<=b;i++)
    #define fd(i,a,b) for(int i=a;i>=b;i--)
    #define rep(i,x) for(int i=head[x];i;i=next[i])
    #define mem(a,x) memset(a,x,sizeof(a))
    typedef long long LL;
    typedef double DB;
    using namespace std;
    inline int read() {
    	int x=0,f=1;char ch=getchar();
    	while(ch<'0'||ch>'9') f=(ch=='-')?-1:f,ch=getchar();
    	while(ch>='0'&&ch<='9') x=x*10+(ch-'0'),ch=getchar();return f*x;
    }
    const int maxn=50000+10;
    const DB esp=1e-9;
    struct line{int id,k,b;line(int _id=1,int _k=0.0,int _b=0.0){id=_id;k=_k;b=_b;}}L[maxn],S[maxn];
    bool operator<(const line&a,const line&b){return (a.k<b.k)||(a.k==b.k&&a.b>b.b);}
    bool operator==(const line&a,const line&b){return a.k==b.k;}
    DB getx(line&a,line&b){return (DB)(b.b-a.b)/(DB)(a.k-b.k);}
    int n,ans[maxn],top=1,x,y;
    int main() {
        n=read();
        fo(i,1,n) x=read(),y=read(),L[i]=line(i,x,y);
        sort(L+1,L+n+1),n=unique(L+1,L+n+1)-L-1;
        fo(i,1,n) {
            while(top>2&&getx(S[top-1],S[top-2])>getx(S[top-1],L[i])-esp)top--;
            S[top++]=L[i];
        }
    	fo(i,1,top-1) ans[i]=S[i].id;
        sort(ans+1,ans+top);
        fo(i,1,top-1) printf("%d ",ans[i]);
    	return 0;
    }
    
  • 相关阅读:
    Python字符串的encode与decode
    python数据操作方法封装
    python的继承
    python常用模块
    python导入模块和包的使用
    python实现curl功能
    [转]Java反射机制详解
    kafka入门
    [转]Servlet的学习之Filter过滤器技术
    [转]Java泛型
  • 原文地址:https://www.cnblogs.com/patricksu/p/8007333.html
Copyright © 2011-2022 走看看