「POJ2932」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 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 conei.
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
1 2 3 4 5 6 |
5 1 0 -2 3 0 3 10 0 0 1 0 1.5 10 50 50 |
Sample Output
1 2 |
2 3 5 |
题解
扫描线。。储存每个圆的左端点和右端点的x坐标。然后从左扫到右。。
若扫描到的是圆的左端点,就判断圆心(y坐标)在其上方且离其最近的圆是否包含此圆,以及圆心(y坐标)在其下方且离其最近的圆是否包含此圆,若包含就continue,不包含就insert到set中;
若扫描到的是圆的右端点,就从set中erase此圆
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<cmath> #include<set> #define inf 1000000000 #define ll long long #define pa pair<double,int> using namespace std; int n,cnt,ans; bool mark[40005]; double x[40005],y[40005],r[40005]; pa l[80005]; set<pa> t; set<pa>::iterator it; bool contain(int a,int b) { return (x[a]-x[b])*(x[a]-x[b])+(y[a]-y[b])*(y[a]-y[b])<=r[b]*r[b]); } int main() { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%lf%lf%lf",&r[i],&x[i],&y[i]); for(int i=1;i<=n;i++) { l[++cnt]=make_pair(x[i]-r[i],i); l[++cnt]=make_pair(x[i]+r[i],i+n); } sort(l+1,l+cnt+1); for(int i=1;i<=cnt;i++) { int now=l[i].second; if(now<=n) { it=t.lower_bound(make_pair(y[now],now)); if(it!=t.end()&&contain(now,it->second))continue; if(it!=t.begin()&&contain(now,(--it)->second))continue; mark[now]=1;ans++; t.insert(make_pair(y[now],now)); } else t.erase(make_pair(y[now-n],now-n)); } printf("%d\n",ans); for(int i=1;i<=n;i++) if(mark[i])printf("%d ",i); return 0; } |