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

    bzoj1007[HNOI2008]水平可见直线

    题意:

    平面上有n条直线L1,L2,...Ln,若在y值为正无穷大处往下看,能见到Li的某个子线段,则称Li为可见的,否则Li为被覆盖的。给出n条直线,已知其斜率和截距,且n条直线两两不重合,求出所有可见的直线。

    题解:

    和上一道差不多,但是因为是比较随意的直线,所以还要多一些判断条件。

    代码:

     1 #include <cstdio>
     2 #include <algorithm>
     3 #include <cstring>
     4 #include <cmath>
     5 #define inc(i,j,k) for(int i=j;i<=k;i++)
     6 #define eps 1e-8
     7 using namespace std;
     8 
     9 struct nd{
    10     int a,b,id;
    11     bool operator < (const nd& x)const{
    12         if(a!=x.a)return a<x.a; return b<x.b;
    13     }
    14 };
    15 double solve(nd a,nd b){
    16     return (double)(a.b-b.b)/(double)(b.a-a.a);
    17 }
    18 nd nds[100000],s[100000]; int ans[100000],n,tp;
    19 int main(){
    20     scanf("%d",&n);inc(i,1,n)scanf("%d",&nds[i].a),scanf("%d",&nds[i].b),nds[i].id=i; sort(nds+1,nds+1+n);
    21     tp=1;s[tp]=nds[1];ans[tp]=nds[1].id;
    22     inc(i,2,n){
    23         if(nds[i].a-s[tp].a==0)tp--;
    24         while(tp>=2&&solve(s[tp-1],s[tp])>=solve(s[tp],nds[i]))tp--;
    25         s[++tp]=nds[i]; ans[tp]=nds[i].id;
    26     }
    27     sort(ans+1,ans+1+tp);inc(i,1,tp)printf("%d ",ans[i]);
    28     return 0;
    29 }

    20160407

  • 相关阅读:
    手动安装mysql
    spring boot 配置注入
    IOS-电话拦截
    重新入坑-IntelliJ Maven
    git使用问题
    Intelij U
    iTunes空间不足无法备份iphone的问题
    Centos7最小化安装
    实操笔记
    centos7中端口及服务对应情况(笔记)
  • 原文地址:https://www.cnblogs.com/YuanZiming/p/5696932.html
Copyright © 2011-2022 走看看