• 原题如下:

    Coneology
    Time Limit: 5000MS   Memory Limit: 65536K
    Total Submissions: 4937   Accepted: 1086

    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
  • 题解:由于有任意两圆都没有公共点这一条件,要判断一个圆是否在其他圆的内部,只要判断其圆心是否在其他圆内即可。这样判断每个圆是否是最外层的复杂度为O(N),因此很容易得到O(N2)复杂度的算法。而利用平面扫描技术可以得到更为高效的算法。
    在几何问题中,经常利用平面扫描技术来降低算法的复杂度。所谓平面扫描,是指扫描线在平面上按给定轨迹移动的同时,不断根据扫描线扫过部分更新信息,从而得到整体所要求的结果的方法。扫描的方法,既可以从左向右平移与y轴平行的直线,也可以固定射线的端点逆时针转动。
    对于这道题而言,我们在从左向右平移与y轴平行的直线的同时,维护与扫描线相交的最外层的圆的集合。从左向右移动的过程中,只有扫描线移动到圆的左右两端时,圆与扫描线的相交关系才会发生变化,因此我们先将所有这样的x坐标枚举出来并排好序。首先,当扫描线移动到某个圆的左端时,我们需要判断该圆是否包含在其他圆中,为此,我们只需从当前与扫描线相交的最外层的圆中,找到上下两侧y坐标方向距离最近的两个圆,并检查它们就足够了,因为,假设该圆被包含与更远的圆中,却不被包含于最近的圆中,就会得出两个圆相交的结论,而这与题目的条件不符,于是,只要用二叉查找树来维护这些圆,就能够在O(logn)时间内取得待检查的圆了。其次,当扫描线移动到某个圆的右端时,如果该圆已经包含于其他圆中就什么也不做,如果是最外层的圆就将它从二叉树中删去。综上,总的复杂度是O(nlogn)。
  • 代码:
    #include <cstdio>
    #include <utility>
    #include <set>
    #include <vector>
    #include <algorithm> using namespace std; const int MAX_N=;
    int N;
    double x[MAX_N], y[MAX_N], r[MAX_N]; 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=; 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=; 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\n", res.size());
    for (int i=; i<res.size(); i++)
    {
    printf("%d%c", res[i]+, i+==res.size() ? '\n' : ' ');
    }
    } int main()
    {
    scanf("%d", &N);
    for (int i=; i<N; i++)
    {
    scanf("%lf%lf%lf", &r[i], &x[i], &y[i]);
    }
    solve();
    }

Coneology(POJ 2932)的更多相关文章

  1. POJ 2932 圆扫描线

    求n个圆中没有被包含的圆.模仿扫描线从左往右扫,到左边界此时如有3个交点,则有3种情况,以此判定该圆是否被离它最近的圆包含,而交点和最近的圆可以用以y高度排序的Set来维护.因此每次到左边界插入该圆, ...

  2. POJ 2932 Coneology(扫描线)

    [题目链接] http://poj.org/problem?id=2932 [题目大意] 给出N个两两没有公共点的圆,求所有不包含于其它圆内部的圆 [题解] 我们计算出所有点在圆心所有y位置的x值, ...

  3. poj 2932 Coneology(扫描线+set)

    Coneology Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 3574   Accepted: 680 Descript ...

  4. POJ 2932 Coneology计算最外层圆个数

    平面上有n个两两没有公共点的圆,i号圆的圆心在(xi,yi),半径为ri,编号从1开始.求所有最外层的,即不包含于其他圆内部的圆.输出符合要求的圆的个数和编号.n<=40000. (注意此题无相 ...

  5. poj 2932 Coneology (扫描线)

    题意 平面上有N个两两不相交的圆,求全部最外层的,即不被其它圆包括的圆的个数并输出 思路 挑战程序竞赛P259页 代码 /* ************************************* ...

  6. TTTTTTTTTTTTTTT poj 2932 Coneology 平面扫描+STL

    题目链接 题意:有n个圆,圆之间不存在相交关系,求有几个不被其他任何圆包含的圆,并输出圆的编号: #include <iostream> #include <cstdio> # ...

  7. POJ 2932 平面扫描 /// 判断圆的包含关系

    题目大意: 平面上有n个两两不相交的圆,给定圆的圆心(x,y)和半径 r 求所有最外层的 即 不包含于其他圆内部的圆 挑战258页 平面扫描 记录所有圆的左端和右端 排序后 逐一扫描 将到当前圆为止的 ...

  8. [扫描线]POJ2932 Coneology

    题意:有n个圆 依次给了半径和圆心坐标  保证输入的圆不相交(只有 相离 和 内含/外含 的情况)   问 有几个圆 不内含在其他圆中,并分别列出这几个圆的编号(1~n) (n的范围是[1, 4000 ...

  9. HDU 3511 圆扫描线

    找最深的圆,输出层数 类似POJ 2932的做法 圆扫描线即可.这里要记录各个圆的层数,所以多加一个维护编号的就行了. /** @Date : 2017-10-18 18:16:52 * @FileN ...

随机推荐

  1. C#LeetCode刷题之#4-两个排序数组的中位数(Median of Two Sorted Arrays)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/4005 访问. 给定两个大小为 m 和 n 的有序数组 nums1 ...

  2. 【建议收藏】swoft的最佳实践

    这是一篇使用 swoft 两个月后的总结文章!,后续会陆续更新的 这是 web-api 开发的总结,如果使用 websocket 等服务的可能不适用,本章节会对一些规范.习惯,或者优化进行一些说明 一 ...

  3. 编写有提示的listbox控件 2008-06-29 17:13

    在MFC中几乎所有的控件都有信息提示,而惟有listbox却没有这样的一个功能,每当我们把鼠标移到listbox上控件时,啥玩意儿都没有是不是很气馁啊,所以我今天特地写了一个简单的有提示的listbo ...

  4. 已废弃_CSDN慕零的黑夜-头条-第一期(必问)[导读:]1.CSDN必问赏金流向何方 2.CSDN必问偷偷做的手脚 3.CSDN必问靠谱吗 4.关于钱于回答的平衡问题:一美元拍卖骗局qq3461896724

    [本文有已知的链接差错,懒得改了] 本期是关于CSDN 必问 (biwen.csdn.net)的内容,欢迎评论文末,文中插入有 小姐姐 img(附py代码,1.49G) + coding资料 哟~~~ ...

  5. ElasticSearch实战系列八: Filebeat快速入门和使用---图文详解

    前言 本文主要介绍的是ELK日志系统中的Filebeat快速入门教程. ELK介绍 ELK是三个开源软件的缩写,分别表示:Elasticsearch , Logstash, Kibana , 它们都是 ...

  6. JavaScript学习系列博客_26_JavaScript 数组的一些方法

    数组的一些方法 - push() - 用来向数组的末尾添加一个或多个元素,并返回数组新的长度 - 语法:数组.push(元素1,元素2,元素N) - pop() - 用来删除数组的最后一个元素,并返回 ...

  7. 【转】Ubuntu下解决Depends: xxx(< 1.2.1) but xxx is to be installed

    在ubuntu下由于更新package不成功,或者误删除了一些文件会出现Depends: xxx(< 1.2.1) but xxx is to be installed解决方法是先试着安装所缺的 ...

  8. ISO8601

    日期和时间的组合表示法 合并表示时,要在时间前面加一大写字母T,如要表示东八区时间2004年5月3日下午5点30分8秒,可以写成2004-05-03T17:30:08+08:00或20040503T1 ...

  9. SPSSAU新功能上线:高级公式、综合得分一键计算!

    一直关注我们的朋友们一定会发现,近期SPSSAU增添了很多新功能. 我们精挑细选出6个最常使用的功能,介绍给大家,看看这些新功能你有没有解锁成功呢? 01 一键删除无效样本 “无效样本”功能中,添加了 ...

  10. 区块链入门到实战(28)之Solidity – 介绍

    Solidity语言是一种面向合约的高级编程语言,用于在以太坊区块链网络上实现智能合约.Solidity语言深受c++.Python和JavaScript的影响,针对以太坊(Ethereum)虚拟机( ...