POJ 2932 —— 计算几何&&平面扫描

Coneology
Time Limit: 5000MS Memory Limit: 65536K
Total Submissions: 2493 Accepted: 413

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

挺有意思的一道计算几何,题意是给你n个圆,告诉你他们的圆心和半径,保证不相交,不相切,让你输出最外层圆的数目。
思路:用一条垂直直线去从x轴负方向扫到x轴正向,我们把每个圆的最左端和最右端作为关键点,当扫到左关键点时去判断该圆是否包含在其他圆内,只要判断是否在离他最近的两个圆内即可,若不在,加入set。当扫到右关键点时,从set中删除该圆。
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <map>
#include <string>
#include <stack>
#include <cctype>
#include <vector>
#include <queue>
#include <set>
#include <utility>
#include <cassert>
using namespace std;
///#define Online_Judge
#define outstars cout << "***********************" << endl;
#define clr(a,b) memset(a,b,sizeof(a))
#define lson l , mid  , rt << 1
#define rson mid + 1 , r , rt << 1 | 1
#define mk make_pair
#define FOR(i , x , n) for(int i = (x) ; i < (n) ; i++)
#define FORR(i , x , n) for(int i = (x) ; i <= (n) ; i++)
#define REP(i , x , n) for(int i = (x) ; i > (n) ; i--)
#define REPP(i ,x , n) for(int i = (x) ; i >= (n) ; i--)
const int MAXN = 40000 + 50;
const int MAXS = 10000 + 50;
const int sigma_size = 26;
const long long LLMAX = 0x7fffffffffffffffLL;
const long long LLMIN = 0x8000000000000000LL;
const int INF = 0x7fffffff;
const int IMIN = 0x80000000;
const int inf = 1 << 30;
#define eps 1e-10
const long long MOD = 1000000000 + 7;
const int mod = 10007;
typedef long long LL;
const double PI = acos(-1.0);
typedef double D;
typedef pair<int , int> pii;
typedef vector<int> vec;
typedef vector<vec> mat;


#define Bug(s) cout << "s = " << s << endl;
///#pragma comment(linker, "/STACK:102400000,102400000")
int n;
double x[MAXN] , y[MAXN] , r[MAXN];
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> > p;
    for(int i = 0 ; i < n; i++)
    {
        p.push_back(mk(x[i] - r[i] , i));
        p.push_back(mk(x[i] + r[i] , i + n));
    }
    sort(p.begin() , p.end());
    set <pair <double  , int> > outs;
    vector <int> ans;
    for(int i = 0 ; i < p.size() ; i++)
    {
        int id = p[i].second % n;
        if(p[i].second < n)
        {
            set <pair <double  , int > > :: iterator it = outs.lower_bound(mk(y[id] , id));
            if(it != outs.end() && inside(id , it -> second))continue;
            if(it != outs.begin() && inside(id , (--it) -> second))continue;
            ans.push_back(id);
            outs.insert(mk(y[id] , id));
        }
        else
        {
            outs.erase(mk(y[id] , id));
        }
    }
    sort(ans.begin() , ans.end());
    printf("%d\n" , ans.size());
    for(int i = 0 ; i < ans.size() ; i++)
    {
        printf("%d%c" , ans[i] + 1 , i + 1 == ans.size() ? '\n' : ' ');
    }
}
int main()
{
    while(~scanf("%d" , &n))
    {
        for(int i = 0 ; i < n ; i++)scanf("%lf%lf%lf" , &r[i] , &x[i] , &y[i]);
        solve();
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值