Coneology(poj2932)

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个两两没有公共点的圆,i号圆的圆心在(xi,yi),半径为ri。求所有最外层的,即不包含于其它圆内部的圆。

解题思路
采用平面扫描,从左到右扫描,将与扫描线相交的最外层的圆加入集合。
在判断该圆是否被其它圆包含时,只需从当前与扫描线相交的最外层的圆中,找到上下两侧y坐标方向距离最近的两个圆并检查他们。
代码如下

#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
int N;
double x[50005],y[50005],r[50005];
bool inside(int i,int j)//判断圆i是否在圆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;圆左右两端的x坐标
    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;//与扫描线相交的最外层圆的集合。注意set是平衡二叉树,存入时已经排好序
    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));//找到距离该圆y坐标最近的上方的圆
            if(it!=outers.end()&&inside(id,it->second)) continue;//上圆
            if(it!=outers.begin()&&inside(id,(--it)->second)) continue;//下圆(因为set是平衡二叉树)
            res.push_back(id);
            outers.insert(make_pair(y[id],id));
        }
        else
        outers.erase(make_pair(y[id],id));
    }
    sort(res.begin(),res.end());
    cout<<res.size()<<endl;
    for(int i=0;i<res.size()-1;i++)
    cout<<res[i]+1<<" ";
    cout<<res[res.size()-1]+1<<endl;
}
int main()
{
    int i;
    while(cin>>N)
    {
        for(int i=0;i<N;i++)
        cin>>r[i]>>x[i]>>y[i];
        solve();
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值