计算几何值平面扫面poj2932 Coneology
|
Coneology
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 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 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 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) 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 Sample Input 5 Sample Output 2 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\n",res.size());
for(int i=0;i<res.size()-1;i++)
{
printf("%d ",res[i]+1);
}
printf("%d\n",res[res.size()-1]+1);
//printf("\n");
}
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;
}
计算几何值平面扫面poj2932 Coneology的更多相关文章
- POJ2932 Coneology【圆扫描线】
POJ2932 Coneology 题意: 给出一些不相交的圆,问有多少个圆不被其他圆包围 题解: 扫描线,把所有圆的左边界和右边界放到\(vector\)里排序,遍历到圆左边界的时候判断是否满足条件 ...
- [扫描线]POJ2932 Coneology
题意:有n个圆 依次给了半径和圆心坐标 保证输入的圆不相交(只有 相离 和 内含/外含 的情况) 问 有几个圆 不内含在其他圆中,并分别列出这几个圆的编号(1~n) (n的范围是[1, 4000 ...
- poj2932 Coneology (扫描线)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Coneology Time Limit: 5000MS Memory Lim ...
- hdu 5784 How Many Triangles 计算几何,平面有多少个锐角三角形
How Many Triangles 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5784 Description Alice has n poin ...
- poj2932 Coneology
地址:http://poj.org/problem?id=2932 题目: Coneology Time Limit: 5000MS Memory Limit: 65536K Total Subm ...
- three.js后期之自定义shader通道实现扫光效果
如果你还不知道如何在three.js中添加后期渲染通道,请先看一下官方的一个最简单的demo : github. 正如demo中所示的那样,我们的扫光效果,也是一个自定义的ShaderPass. 所以 ...
- 游戏编程算法与技巧 Game Programming Algorithms and Techniques (Sanjay Madhav 著)
http://gamealgorithms.net 第1章 游戏编程概述 (已看) 第2章 2D图形 (已看) 第3章 游戏中的线性代数 (已看) 第4章 3D图形 (已看) 第5章 游戏输入 (已看 ...
- SCOI2015
这周各种头疼,一直睡觉+发呆,啥子都没干. 就补一下之前的东西. d1t1小凸玩矩阵 传送门 一开始脑子抽写了最小费用最大流,不知道自己怎么想的. 第k大最小,明显的二分,又是二分图,二分第k大值,把 ...
- BZOJ 4614 【Wf2016】 Oil
题目链接:Oil 感觉同时几线作战有点吃不消啊-- 这道题有一个显然的结论,那就是最优的直线一定过某条线段的端点. 仔细想想很有道理.如果最终的直线没有过线段的端点的话,那么这条直线就一定可以平移,直 ...
随机推荐
- Vue 实例以及生命周期
最简单的 Vue 实例 //html <div id="app"> {{message}} </div> //javascript var vm = new ...
- [bzoj4698][Sdoi2008]Sandy的卡片_后缀数组_二分/单调队列_双指针
Sandy的卡片 bzoj-4698 Sdoi-2008 题目大意:题目链接. 注释:略. 想法: 这个题跟一个Usaco的题特别像.我们把这些串差分 现在我们要求的就是公共子串且出现次数不少于$k$ ...
- echarts模拟highcharts实现折线图的虚实转换
多的不说直接上代码: <html><html lang="en"><head> <meta charset="utf-8&quo ...
- JDBC的Statement对象
以下内容引用自http://wiki.jikexueyuan.com/project/jdbc/statements.html: 一旦获得了数据库的连接,就可以和数据库进行交互.JDBC的Statem ...
- openstack setup demo Enviroment
Enviroment 本文包含以下部分. Host networking Network Time Protocol (NTP) OpenStack packages SQL database NoS ...
- Mysql中错误日志、binlog日志、查询日志、慢查询日志简单介绍
前言 数据库的日志是帮助数据库管理员,追踪分析数据库以前发生的各种事件的有力根据.mysql中提供了错误日志.binlog日志(二进制日志).查处日志.慢查询日志.在此,我力求解决下面问题:各个日志的 ...
- maven 手动构建项目
maven 手动构建项目 在空目录下面: D:\test>mvn -B archetype:generate -DarchetypeGroupId=org.apache.maven.archet ...
- 小白学开发(iOS)OC_ 字符串的获取 (2015-08-11)
// // main.m // 字符串的获取 // // Created by admin on 15/8/13. // Copyright (c) 2015年 admin. All righ ...
- iOS社交分享Twitter、Facebook、拷贝到剪切板、LINE、及邮件
准备 首先要引进例如以下三个framework: MessageUI.framework Social.framework Accounts.framework 并在实现这几个方法的地方引入下面几个头 ...
- Android 圆形/圆角图片的方法
Android 圆形/圆角图片的方法 眼下网上有非常多圆角图片的实例,Github上也有一些成熟的项目.之前做项目,为了稳定高效都是选用Github上的项目直接用.但这样的结束也是Android开发必 ...