lundi 16 mars 2015

Partition Frisbees C++


We have a set F of n frisbee's in 2D. We want to partition F into two subsets F1, and F2 so that no two frisbee's intersect in each respective subset. Our function takes in input as so: (x_j, y_j) is the centre of the j-th frisbee, and rad_j is the radius of the j-th frisbee. The output should be s_0 s_1 ... s_n-1, where s_j = 1 if the j-th frisbee is in F1 and s_i = 2 if the j-th frisbee is in F2. If you cannot partition F, just return 0. Ideally, the algo should be computed in O(n^2) time.


I figured that I should use some type type of matrix representation of this like graph, but then I don't think I need need to construct a graph, but I think I BFS/DFS would be useful, but I'm stuck on how exactly to do this elegantly in O(n^2). I am coding this in C++ by the way.




Aucun commentaire:

Enregistrer un commentaire