刷题总结——coneology(poj2932 扫描线)
题目:
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
题解:
思路参见:http://www.cppblog.com/Wangzhihao/articles/109348.html
这道题能想到扫描线也是佩服啊······通过这道题也学到了set里加pair还有指针的骚操作
代码:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cctype>
#include<set>
using namespace std;
set<pair<double,int> >st;
const int N=8e5+;
double x[N],y[N],r[N];
int ans[N],cnt,n;
struct node
{
double x;int id,op;
}q[N];
inline bool cmp(node a,node b)
{
return a.x<b.x;
}
inline bool jud(int a,int b)
{
return (x[a]-x[b])*(x[a]-x[b])+(y[a]-y[b])*(y[a]-y[b])<=(r[a]-r[b])*(r[a]-r[b]);
}
int main()
{
//freopen("a.in","r",stdin);
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%lf%lf%lf",&r[i],&x[i],&y[i]);
q[i].x=x[i]-r[i],q[i].id=i,q[i].op=;
q[i+n].x=x[i]+r[i],q[i+n].id=i,q[i+n].op=-;
}
sort(q+,q+*n+,cmp);
for(int i=;i<=*n;i++)
{
if(q[i].op==)
{
set<pair<double,int> > ::iterator l=st.lower_bound(make_pair(y[q[i].id],q[i].id));
if(l!=st.end()&&jud(q[i].id,l->second)) continue;
if(l!=st.begin()&&jud(q[i].id,(--l)->second)) continue;
ans[++cnt]=q[i].id;
st.insert(make_pair(y[q[i].id],q[i].id));
}
else
st.erase(make_pair(y[q[i].id],q[i].id));
}
cout<<cnt<<endl;
sort(ans+,ans+cnt+);
for(int i=;i<=cnt;i++)
cout<<ans[i]<<" ";
return ;
}
刷题总结——coneology(poj2932 扫描线)的更多相关文章
- $2019$ 暑期刷题记录1:(算法竞赛DP练习)
$ 2019 $ 暑期刷题记录: $ POJ~1952~~BUY~LOW, BUY~LOWER: $ (复杂度优化) 题目大意:统计可重序列中最长上升子序列的方案数. 题目很直接的说明了所求为 $ L ...
- LeetCode刷题系列
LeetCode 我们工作面试和提高自身数据结构和算法能力的时候往往需要刷刷题,我选择LeetCode是通过一个留学论坛了解的.专业,覆盖语种全面. 提前说说刷题的心得: 尽量手写代码,少使用IDE的 ...
- ife任务刷题总结(一)-css reset与清除浮动
本文同时发布于本人的个人网站www.yaoxiaowen.com 百度创办的前端技术学院,是一个面向大学生的前端技术学习平台.虽然只有大学生才有资格报名,提交代码进行比赛排名.但是这并不妨碍我们这些初 ...
- 刷题ING...
我用codeVS刷题.. 努力准备!!
- XidianOJ 1020 ACMer去刷题吧
题目描述 刷题是每个ACMer必由之路,已知某oj上有n个题目,第i个题目小X能做对的概率为Pi(0<=Pi<=1,1<=i<=n) 求小X至少做对k道题的概率 输入 第一行输 ...
- 【BZOJ-4590】自动刷题机 二分 + 判定
4590: [Shoi2015]自动刷题机 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 156 Solved: 63[Submit][Status ...
- NOI题库分治算法刷题记录
今天晚自习机房刷题,有一道题最终WA掉两组,极其不爽,晚上回家补完作业欣然搞定它,特意来写篇博文来记录下 (最想吐槽的是这个叫做分治的分类,里面的题目真的需要分治吗...) 先来说下分治法 分治法的设 ...
- NOI题库刷题日志 (贪心篇题解)
这段时间在NOI题库上刷了刷题,来写点心得和题解 一.寻找平面上的极大点 2704:寻找平面上的极大点 总时间限制: 1000ms 内存限制: 65536kB 描述 在一个平面上,如果有两个点( ...
- 用js刷题的一些坑
leecode可以用js刷题了,我大js越来越被认可了是吧.但是刷题中会因为忽略js的一些特性掉入坑里.我这里总结一下我掉过的坑. 坑1:js中数组对象是引用对象 js中除了object还有数组对象也 ...
随机推荐
- FMDB浅析(思想)
http://www.cnblogs.com/OTgiraffe/p/5931800.html 一.FMDB介绍 FMDB是一种第三方的开源库,FMDB就是对SQLite的API进行了封装,加上了面向 ...
- python_98_面向对象_学校
class School(object):#以后都加object(基类) def __init__(self, name, addr): self.name = name self.addr = ad ...
- 关于tomcat的classloader的一点想法
关于tomcat的classloader相关的帖子网上非常多,我觉得比较好的有: https://www.jianshu.com/p/d90e4430b0b9 https://blog.csdn.ne ...
- 【转】 树莓派初次启动攻略for Mac
http://blog.csdn.net/rk2900/article/details/8632713/ 树莓派初次启动攻略for Mac made by Rk 感谢浙江大学<嵌入式系统> ...
- MFC:AfxSetResourceHandle
AfxGetResourceHandle用于获取当前资源模块句柄. 而AfxSetResourceHandle则用于设置程序目前要使用的资源模块句柄,一般在InitInstance()里调用.
- 如何下载js类库
https://bower.io/ 这个已经淘汰 https://learn.jquery.com/jquery-ui/environments/bower/ Web sites are made ...
- CVE-2014-1767
[0x00].简介 CVE-2014-1767漏洞是由于Windows的afd.sys驱动在对系统内存的管理操作中,存在着悬垂指针的问题.在特定情况下攻击者可以通过该悬垂指针造成内存的double ...
- 汉明码(Hamming Code)原理及实现
汉明码实现原理 汉明码(Hamming Code)是广泛用于内存和磁盘纠错的编码.汉明码不仅可以用来检测转移数据时发生的错误,还可以用来修正错误.(要注意的是,汉明码只能发现和修正一位错误,对于两位或 ...
- jquery Syntax error, unrecognized expression:的解决方法
原文地址 https://blog.csdn.net/flowingfog/article/details/42739773 问题: 将模板的html内容转换成jquery时报以下错误:Syntax ...
- PHP获取文件夹内所有文件包括子目录文件的名称或路径
/* * new getFile($_dir[,$_emptyDir,$_fileType]); * @parma $_dir 是目录名称 * @parma $_emptyDir 是否获取空文件夹,选 ...