zoukankan      html  css  js  c++  java
  • [bzoj1007][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

    Solution

    #include <cmath>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    #define MAXN 50010
    #define Eps 1e-18
    
    using namespace std;
    
    struct Liyn{
      int k, b, pos;
    
      void Push(int i) {scanf("%d%d", &k, &b); pos = i;}
    
      bool operator == (const Liyn &a)const {return k == a.k;}
    
      bool operator < (const Liyn &a)const {return k < a.k || (k == a.k && b > a.b);}
    
      double Cmp(const Liyn &a) {return double(a.b - b) / double(k - a.k);}
    }L[MAXN], _pb[MAXN];
    
    int n, top, ans[MAXN];
    
    int main(){
      scanf("%d", &n);
      for(int i = 0; i < n; i++)
        L[i].Push(i);
      sort(L, L + n);
      n = unique(L, L + n) - L;
      for(int i = 0; i < n; i++){
        while(top > 1 && _pb[top - 1].Cmp(_pb[top - 2]) > L[i].Cmp(_pb[top - 1]) - Eps)top--;
        _pb[top++] = L[i];
      }
      for(int i = 0; i < top; i++)
        ans[i] = _pb[i].pos;
      sort(ans, ans + top);
      for(int i = 0; i < top; i++)
        printf("%d ", ans[i] + 1);
      return 0;
    }
  • 相关阅读:
    windows 环境下 eclipse + maven + tomcat 的 hello world 创建和部署
    使用IntelliJ IDEA 14和Maven创建java web项目
    使用Spring JDBCTemplate简化JDBC的操作
    CSS颜色代码 颜色值 颜色名字大全
    mysql创建数据库命令
    win64位安装python-mysqldb1.2.3
    UVA11426 欧拉函数
    关于gcd的几个问题
    POI2007_zap 莫比乌斯反演
    BZOJ2005 莫比乌斯反演
  • 原文地址:https://www.cnblogs.com/keshuqi/p/6240399.html
Copyright © 2011-2022 走看看