zoukankan      html  css  js  c++  java
  • bzoj 1007 : [HNOI2008]水平可见直线 计算几何

    题目链接

    给出n条直线, 问从y轴上方向下看, 能看到哪些直线, 输出这些直线的编号。

    首先我们按斜率排序, 然后依次加入一个栈里面, 如果刚加入的直线, 和之前的那条直线斜率相等, 那么显然之前的会被覆盖。

    假设栈顶直线为st[top], 新加入的直线为tmp, 那么如果tmp和st[top-1]这条直线的交点在st[top]和st[top-1]交点的左边, 那么显然st[top]这条直线会被覆盖。

    #include <iostream>
    #include <vector>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #include <map>
    #include <set>
    #include <string>
    #include <queue>
    #include <stack>
    #include <bitset>
    using namespace std;
    #define pb(x) push_back(x)
    #define ll long long
    #define mk(x, y) make_pair(x, y)
    #define lson l, m, rt<<1
    #define mem(a) memset(a, 0, sizeof(a))
    #define rson m+1, r, rt<<1|1
    #define mem1(a) memset(a, -1, sizeof(a))
    #define mem2(a) memset(a, 0x3f, sizeof(a))
    #define rep(i, n, a) for(int i = a; i<n; i++)
    #define fi first
    #define se second
    typedef pair<int, int> pll;
    const double PI = acos(-1.0);
    const double eps = 1e-8;
    const int mod = 1e9+7;
    const int inf = 1061109567;
    const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };
    struct node
    {
        double x, y;
        int id;
        bool operator < (node a) const
        {
            if(fabs(x-a.x)<eps)
                return y<a.y;
            return x<a.x;
        }
    }a[50005], st[50005];
    int top, ans[50005];
    double cross(node a, node b) {
        return (b.y-a.y)/(a.x-b.x);
    }
    void add(node tmp) {
        while(top) {
            if(fabs(tmp.x-st[top].x)<eps)
                top--;
            else if(top>1 && cross(tmp, st[top-1])<=cross(st[top], st[top-1]))
                top--;
            else
                break;
        }
        st[++top] = tmp;
    }
    int main()
    {
        int n;
        cin>>n;
        for(int i = 0; i<n; i++) {
            scanf("%lf%lf", &a[i].x, &a[i].y);
            a[i].id = i;
        }
        sort(a, a+n);
        for(int i = 0; i<n; i++) {
            add(a[i]);
        }
        for(int i = 1; i<=top; i++) {
            ans[st[i].id] = 1;
        }
        for(int i = 0; i<n; i++)
            if(ans[i])
                printf("%d ", i+1);
        cout<<endl;
        return 0;
    }
  • 相关阅读:
    Module Error (from ./node_modules/@dcloudio/vue-cli-plugin-uni/packages/vue-loader/lib/loaders/templ
    二面角的平面角求法
    异面直线所成的角
    分式函数与高考数学
    备考反思|2021年全国卷乙卷理科数学解析版
    2021年全国卷乙卷理科数学图片版
    备考反思|2021年全国卷乙卷文科数学解析版
    2021年 全国卷乙卷文科数学图片版
    数学解题的减法和加法
    三角函数的定义
  • 原文地址:https://www.cnblogs.com/yohaha/p/5221079.html
Copyright © 2011-2022 走看看