POJ2932 Coneology【圆扫描线】
2024-10-19 05:50:28
POJ2932 Coneology
题意:
给出一些不相交的圆,问有多少个圆不被其他圆包围
题解:
扫描线,把所有圆的左边界和右边界放到\(vector\)里排序,遍历到圆左边界的时候判断是否满足条件,到右边界的时候把这个圆从\(set\)中删掉,对于一个选到当前左边界的圆,因为不存在相交,所以只需要判断与他\(y\)坐标最近的两个在\(set\)中的圆是否包含他即可
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<string>
#include<algorithm>
#include<stack>
using namespace std;
void ____(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); }
const int MAXN = 4e4+7;
int n;
double x[MAXN],y[MAXN],r[MAXN];
bool check(int ida, int idb){
/* check if circle[ida] include in circle[idb] */
double dx = x[ida] - x[idb], dy = y[ida] - y[idb];
return r[idb] * r[idb] > dx * dx + dy * dy;
}
void solve(){
for(int i = 1; i <= n; i++) scanf("%lf %lf %lf",&r[i],&x[i],&y[i]);
vector<pair<double,int> > vec;
for(int i = 1; i <= n; i++){
vec.push_back(make_pair(x[i]-r[i],i));
vec.push_back(make_pair(x[i]+r[i],-i));
}
set<pair<double,int> > S;
vector<int> V;
sort(vec.begin(),vec.end());
for(int i = 0; i < (int)vec.size(); i++){
int id = abs(vec[i].second);
if(vec[i].second<0) S.erase(make_pair(y[id],id));
else{
set<pair<double,int> >::iterator it = S.lower_bound(make_pair(y[id],-1));
bool inc = false;
if((it!=S.end() and check(id,it->second)) or (it!=S.begin() and check(id,(--it)->second))) inc = true;
if(!inc) S.insert(make_pair(y[id],id)), V.push_back(id);
}
}
printf("%d\n",V.size());
sort(V.begin(),V.end());
for(int i = 0; i < (int)V.size(); i++) printf("%d ",V[i]);
puts("");
}
int main(){
while(scanf("%d",&n)!=EOF) solve();
return 0;
}
最新文章
- SQL Server 深入解析索引存储(下)
- phonegap android 输入法弹出会遮盖表单框的解决办法
- sql复制表
- CSS控制 table 的 cellpadding,cellspacing
- java_Cookie添加和删除
- MySQL数据库的优化-运维架构师必会高薪技能,笔者近六年来一线城市工作实战经验
- linux和windows之间上传 下载文件 非ftp方式
- 黑洞版视频裂变程序【接口版】全新上线,全新UI,支持分享数据统计
- 用SVG做background image
- node auto run / node 自动运行
- 03 Go 1.3 Release Notes
- ROS知识(12)----cv_bridge依赖opencv版本的问题
- 使用Scala
- 【总结整理】关于挪车和虚拟号的思考-转载v2ex
- NYOJ 208 Supermarket (模拟+并查集)
- Transcation And Lock--SQL SERVER 事务隔离级别
- oozie安装总结
- go实现定时功能两种方法
- Linux 总结2
- nginx 查看接口请求时间 每个请求图片的时间或者文件的
热门文章
- 【MySQL 高级】架构介绍
- 【Dart】语言概述
- Head First 设计模式 —— 14. 复合 (Compound) 模式
- 安装sendmail
- 创建一个简单MyBatis程序
- 【Linux】dlopen failed: /lib/lsiRAID.so: cannot open shared object file: No such file or directory
- Docker安装配置及华为云镜像加速
- Vijos-P1103题解【线段树】
- atlas读写分离
- Linux日志文件(常见)及其功能