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 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
题目大意:
平面上有n个两两没有公共点的圆(n <= 40000), i号圆的圆心在(xi, yi),半径为ri.
求所有最外层的, 即不包含于其他圆内部的圆。
平面扫描
用一个set维护扫描线扫到的外层圆
基于圆和圆之间两两不相交,
在扫到某一圆O(x, y)的最左端时,
若set内同一方向圆心的y坐标与当前圆心y最近的圆不包含该圆
则该圆是外层圆, 将其加入set
在扫到圆的右端时, 将该圆从set中删除
详见挑战Page258
#include
#include
#include
using namespace std;
const int MaxN = 40010;
struct data{
double x;
int id;
data () {}
data (double y, int k) {
x = y, id = k;
}
inline bool operator < (const data &b) const {
return x < b.x;
}
}A[MaxN << 1];
set
s;
int n, vis[MaxN], que[MaxN], qn;
double r[MaxN], x[MaxN], y[MaxN];
bool inside (int a, int b) { //判断圆a是否在圆b内(由于不相交,可以直接判点a是否在圆b内)
double xi = x[a] - x[b], yi = y[a] - y[b];
return xi * xi + yi * yi <= 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) {
A[i] = data(x[i] - r[i], i);
A[i + n] = data(x[i] + r[i], i);
}
sort(A + 1, A + (n << 1) + 1);
for (int i = 1; i <= n << 1; ++i)
if (vis[A[i].id] ^ 1) {
vis[A[i].id] = 1;
set :: iterator it = s.lower_bound(data(y[A[i].id], A[i].id)); if (it != s.end() && inside(A[i].id, it->id)) continue; if (it != s.begin() && inside(A[i].id, (--it)->id)) continue; que[++qn] = A[i].id; s.insert(data(y[A[i].id], A[i].id)); } else s.erase(data(y[A[i].id], A[i].id)); sort(que + 1, que + qn + 1); printf("%d\n", qn); for (int i = 1; i <= qn; ++i) printf("%d ", que[i]); }