poj 2932 Coneology

http://poj.org/problem?id=2932

 

题意:

给出n个相离或包含的圆,问哪些圆没有被包含

 

第一次做圆的扫描线

扫面线扫圆形的条件:圆与圆之间只能是相离或包含,不能相交

基本思路是

扫描线从左到右扫,扫到圆的最左边,就把这个圆加入平衡树(用set即可),扫到圆的最右边,就把这个圆从平衡树里拿出来。

从上往下扫同理

 

本题在把圆加入set之前,判断该圆是否与set里的圆都相离,若都相离,才可加入。

若扫描线从左向右扫,只需判断该圆与其在set中圆心纵坐标上面一个、下面一个是否相离即可

 

#include<set>
#include<cmath>
#include<cstdio>
#include<vector>
#include<iostream>
#include<algorithm>

using namespace std; 

#define N 40001

typedef pair<double,int> pr;

set<pr>s;
vector<pr>v;

double r[N],x[N],y[N];

int ans,out[N];

bool judge(int i,int j)
{
    return pow(x[i]-x[j],2)+pow(y[i]-y[j],2)>pow(r[i]+r[j],2);
}

int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;++i) 
    {
        scanf("%lf%lf%lf",&r[i],&x[i],&y[i]);
        v.push_back(pr(x[i]-r[i],i));
        v.push_back(pr(x[i]+r[i],i+n));
    }
    sort(v.begin(),v.end());
    int m=n<<1,k;
    set<pr>:: iterator it;
    for(int i=0;i<m;++i)
    {
        k=v[i].second%n;
        if(v[i].second<n)
        {
            it=s.lower_bound(pr(y[k],k));
            if(it!=s.end() && !judge(it->second,k)) continue;
            if(it!=s.begin() && !judge((--it)->second,k)) continue;
            out[++ans]=k+1;
            s.insert(pr(y[k],k));
        }
        else s.erase(pr(y[k],k));
    }
    printf("%d\n",ans);
    sort(out+1,out+ans+1);
    for(int i=1;i<=ans;++i) printf("%d ",out[i]);
}

 

Coneology
Time Limit: 5000MS   Memory Limit: 65536K
Total Submissions: 5258   Accepted: 1181

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

Source

posted @ 2020-01-17 09:44  TRTTG  阅读(206)  评论(0编辑  收藏  举报