zoukankan      html  css  js  c++  java
  • 计算几何值平面扫面poj2932 Coneology

    Coneology
    Time Limit: 5000MS   Memory Limit: 65536K
    Total Submissions: 4097   Accepted: 859

    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 Rii = 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 Rixiyi separated by spaces, where (xiyi) 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

    Source

    [Submit]   [Go Back]   [Status]   [Discuss]



    题意:平面上有N个两两没有公共点的圆,要求所有最外层,即不包含于其他圆内部的圆的数量。


    由于任意两个圆都没有交点,要判断一个圆是否在其他圆的内部,只要判断其圆心是否在其他圆的内部即可。这样判断每个院是否是最外层的复杂度是O(n);因此很容易得到O(N^2)的算法。接下来解释一种利用平面扫描这一技术得到更为高效的算法。


    在几何问题中,我们经常利用平面扫描技术来降低算法的复杂度。所谓平面扫描,是指扫描线在平面上按给定轨迹移动的同时,不断根据扫描线扫过部分更新信息,从而得到整体要求的结果的方法。扫描的方法,即可以从左到右平移与y轴平行的直线,也可以固定射线的一段一逆时针转动。


    对于本题而言,我们可以从左到右平移与y轴平行的直线的同时,维护与扫描线相交的最外层的圆的集合。从左向右移动的过程中,只有扫描线移动到圆的左右两端时,圆与扫描线的相交关系才会发生变化,因此我们先将所有的这样的x坐标枚举出来并排好序。

    (时刻记住任意两圆不相交)


    首先,我们来看一下扫描线移动到某个圆左端时的情形。此时我们需要判断该圆是否包含在其他圆中。为此,我们只需从当前与扫描线相交的最外层圆中,找到上下两侧y坐标方向距离最近的两个圆,并检查他们就足够了。这是因为,假设该圆被包含于更远的圆中,却不被包含于更近的圆中,这显然不可能出现。于是,只要用二叉树来维护这些圆,就能够子在O(log n)时间内取得待检查的圆了。


    其次,我们看一下扫描线移动到某个圆的右端的情形。此时的处理很简单,如果该圆已经包含在其他圆中就什么都不做,如果是最外层的圆就将它从二叉树中删去。综上,总的时间复杂度是O(nlog n).

    #include <iostream>
    #include<vector>
    #include<stdio.h>
    #include<set>
    #include<string.h>
    #include<algorithm>
    using namespace std;
    const int maxn=5e4+10;
    
    
    int N;
    double x[maxn],y[maxn],r[maxn];
    //判断圆i是否在圆j的内部
    bool inside(int i,int j)
    {
        double dx=x[i]-x[j],dy=y[i]-y[j];
        return dx*dx+dy*dy<=r[j]*r[j];
    }
    void solve()
    {
        //枚举关键点
        vector<pair<double,int> >events;
        for(int i=0;i<N;i++)
        {
            events.push_back(make_pair(x[i]-r[i],i));//圆的左端
            events.push_back(make_pair(x[i]+r[i],i+N));//圆的右端
    
        }
        sort(events.begin(),events.end());
    
        //平面扫描
        set<pair<double,int> >outers;//与扫描线相交的最外层的圆的集合
        vector<int>res;//最外层圆的列表
        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=outers.lower_bound(make_pair(y[id],id));//二分查找
                if(it!=outers.end()&&inside(id,it->second))continue;
                    if(it!=outers.begin()&&inside(id,(--it)->second))continue;
            res.push_back(id);
            outers.insert(make_pair(y[id],id));
            }
            else
            {
                outers.erase(make_pair(y[id],id));
            }
        }
        sort(res.begin(),res.end());
        printf("%d
    ",res.size());
        for(int i=0;i<res.size()-1;i++)
        {
            printf("%d ",res[i]+1);
        }
        printf("%d
    ",res[res.size()-1]+1);
        //printf("
    ");
    }
    int main()
    {
        
        scanf("%d",&N);
        for(int i=0;i<N;i++)
            scanf("%lf%lf%lf",&r[i],&x[i],&y[i]);
        solve();
        return 0;
    }
    





  • 相关阅读:
    rails 与 mysql 5.X for win不兼容
    Ruby开发环境的终极配置(Railsinstaller1.3.0+mysql5.1.61)
    irb的子会话
    Table.ReorderColumns移动…Reorder…(Power Query 之 M 语言)
    Vlookup大叔与一对多查找(Excel函数集团)
    Table.FillDown填充Table.Fill…(Power Query 之 M 语言)
    转置Table.Transpose(Power Query 之 M 语言)
    合并函数Combiner.Combine…(Power Query 之 M 语言)
    List.Sum…统计信息(Power Query 之 M 语言)
    透视列Table.Pivot一维转二维(Power Query 之 M 语言)
  • 原文地址:https://www.cnblogs.com/bryce1010/p/9387292.html
Copyright © 2011-2022 走看看