zoukankan      html  css  js  c++  java
  • POJ-2932 Coneology[平面扫描]

    Coneology

    Time Limit: 5000MS

    Description

    A student named Round Square loved to play with cones. He would arrange cones with different base radii arbitrarily on the floor and would admire the intrinsic beauty of the arrangement. The student even began theorizing about how some cones dominate other cones: a cone A dominates another cone B when cone B is completely within the cone A. Furthermore, he noted that there are some cones that not only dominate others, but are themselves dominated, thus creating complex domination relations. After studying the intricate relations of the cones in more depth, the student reached an important conclusion: there exist some cones, all-powerful cones, that have unique properties: an all-powerful cone is not dominated by any other cone. The student became so impressed by the mightiness of the all-powerful cones that he decided to worship these all-powerful cones.

    Unfortunately, after having arranged a huge number of cones and having worked hard on developing this grandiose cone theory, the student become quite confused with all these cones, and he now fears that he might worship the wrong cones (what if there is an evil cone that tries to trick the student into worshiping it?). You need to help this student by finding the cones he should worship.

    Input

    The input le specifies an arrangement of the cones. There are in total N cones (1 ≤ N ≤ 40000). Cone i has radius and height equal to Ri, i = 1 … N. Each cone is hollow on the inside and has no base, so it can be placed over another cone with smaller radius. No two cones touch.

    The first line of the input contains the integer N. The next N lines each contain three real numbers Ri, xi, yi separated by spaces, where (xi, yi) are the coordinates of the center of the base of cone i.

    Output

    The first line of the output le should contain the number of cones that the student should worship. The second line contains the indices of the cones that the student should worship in increasing order. Two consecutive numbers should be separated by a single space.

    Sample Input

    5
    1 0 -2
    3 0 3
    10 0 0
    1 0 1.5
    10 50 50

    Sample Output

    2
    3 5

    题意:给出n个不相交的圆,求出最外层的圆,也就是不在其他圆内部的圆。

    思路:

    这是挑战上平面扫描的一个例题。扫描线的思想比较好理解,就是一条直线在不断的扫描的过程中更新信息。

    对于这道题而言,直线平行于y轴从左到扫描,每次到达一个圆的最左边,找的和这个圆最近两个圆的y坐标,检查这两个圆和当前的位置。每次从最左边开始,保证的最外面的圆是首先进入。

    #include "stdio.h"
    #include "math.h"
    #include "vector"
    #include "set"
    #include "algorithm"
    using namespace std;
    const int maxn = 4e4 + 10;
    int N;
    struct Cri {
        double x, y, r;
    };
    Cri c[maxn];
    bool inside(int i, int j) {
        double dx = c[i].x - c[j].x, dy = c[i].y - c[j].y;
        return dx*dx+dy*dy <= c[j].r*c[j].r;
    }
    vector<int> res;
    vector<pair<double, int>> events;
    set<pair<double, int>> outs;
    int main(int argc, char const *argv[])
    {
        scanf("%d", &N);
        for (int i = 0; i < N; i++) {
            scanf("%lf %lf %lf", &c[i].r, &c[i].x, &c[i].y);
            events.push_back(make_pair(c[i].x - c[i].r, i));
            events.push_back(make_pair(c[i].x + c[i].r, i + N));
        }
        sort(events.begin(),events.end());
        for (int i = 0; i < events.size(); i++) {    
            int id = events[i].second%N;
            if (events[i].second < N) {
                set<pair<double, int>>::iterator it = outs.lower_bound(make_pair(c[id].y, id));
                if (it != outs.end() && inside(id, it->second)) continue;
                if (it != outs.begin() && inside(id, (--it)->second)) continue;
                res.push_back(id);
                outs.insert(make_pair(c[id].y, id));
             }
             else outs.erase(make_pair(c[id].y, id));
        }
        sort(res.begin(), res.end());
        printf("%d
    ", res.size());
        for (int i = 0; i < res.size(); i++) {
            printf("%d%c", res[i]+1, i+1==res.size()? '
    ':' ');
        }
        return 0;
    }
  • 相关阅读:
    Linux工具之man手册彩色页设置
    使用bakefile编译C工程代码
    学会使用简单的 MySQL 常用操作
    Mysql数据库的通用安装方法
    从Mysql数据库中导入导出表结构
    CentOS下安装MySQL数据库
    lua函数调用
    innodb记录延迟删除对于其它DB操作的影响
    从apache派生cgi工作路径看软链接
    两台主机互为网关是否会像打乒乓球一样一直互发
  • 原文地址:https://www.cnblogs.com/cniwoq/p/7623496.html
Copyright © 2011-2022 走看看