刷题总结——coneology(poj2932 扫描线)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了刷题总结——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+5; 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=1;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=1; q[i+n].x=x[i]+r[i],q[i+n].id=i,q[i+n].op=-1; } sort(q+1,q+2*n+1,cmp); for(int i=1;i<=2*n;i++) { if(q[i].op==1) { 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+1,ans+cnt+1); for(int i=1;i<=cnt;i++) cout<<ans[i]<<" "; return 0; }
以上是关于刷题总结——coneology(poj2932 扫描线)的主要内容,如果未能解决你的问题,请参考以下文章