poj 2932 Coneology(扫描线+set)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了poj 2932 Coneology(扫描线+set)相关的知识,希望对你有一定的参考价值。
Time Limit: 5000MS | Memory Limit: 65536K | |
Total Submissions: 3574 | Accepted: 680 |
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
Source
【思路】
扫描线
将一个园最左点与最右点看作事件,按从左向右的顺序扫描。
如果扫描到最左点则判断在其上方和下方且最近的圆的包含关系,当不被上下两圆包含时累计答案。
如果最右点则删除该圆。
用set组织数据以实现查找与删除的功能。
【代码】
1 #include<set> 2 #include<map> 3 #include<cmath> 4 #include<cstdlib> 5 #include<cstdio> 6 #include<cstring> 7 #include<algorithm> 8 #define mp(a,b) make_pair(a,b) 9 #define FOR(a,b,c) for(int a=(b);a<=(c);a++) 10 #define pr pair<double,int> 11 using namespace std; 12 13 const int N = 40000+10; 14 15 double x[N],y[N],r[N]; 16 pr l[N*2]; int tot; 17 set<pr> S; 18 set<pr> ::iterator it; 19 int n,ans,vis[N]; 20 21 bool inside(int a,int b) { 22 return (x[a]-x[b])*(x[a]-x[b])+(y[a]-y[b])*(y[a]-y[b])<=r[b]*r[b]; 23 } 24 25 int main() { 26 scanf("%d",&n); 27 FOR(i,1,n) scanf("%lf%lf%lf",&r[i],&x[i],&y[i]); 28 FOR(i,1,n) { 29 l[++tot]=mp(x[i]-r[i],i); 30 l[++tot]=mp(x[i]+r[i],i+n); 31 } 32 sort(l+1,l+tot+1); 33 FOR(i,1,tot) { 34 int now=l[i].second; 35 if(now<=n) { 36 it=S.lower_bound(mp(y[now],now)); 37 if(it!=S.end() && inside(now,it->second)) continue; 38 if(it!=S.begin() && inside(now,(--it)->second)) continue; 39 vis[now]=1; ans++; 40 S.insert(mp(y[now],now)); 41 } 42 else 43 S.erase(mp(y[now-n],now-n)); 44 } 45 printf("%d\n",ans); 46 FOR(i,1,n) if(vis[i]) printf("%d ",i); 47 return 0; 48 }
以上是关于poj 2932 Coneology(扫描线+set)的主要内容,如果未能解决你的问题,请参考以下文章