We have set F of N Freebib in 2D, we want to split F into two subsets F1 and F2 , So that there is no difference between the two frisbee in each related subscript. Our function takes equally in input: (x_j, y_j) is the center of Jammu-FribiBb, and radi_j is the radius of J-Fribibi, output should be s_0 s_1 ... s_n-1, where s_j = 1 if j- fr frisbee F1 and s_i = 2 if j-th frisbee is in F2. If you can not divide F, then just return to 0. Ideally, the OO should be calculated in O (N ^ 2) time.
I thought that I should represent some kind of matrix of this type of graph, but then I do not think I need to create a graph, but I think I would be useful to BFS / DFS , But I'm stuck on how I am doing it beautifully (O ^ 2) in an honest way. I'm coding it in C ++
You were on a right track with a graph search . There is a C + 11, O (V ^ 2), deeply before the search solution which uses O (V + E) space
DFS is O (V + E) at the same time, But O (V ^ 2) is a clear way of generating accumulation lists.
#include & lt; Iostream & gt; # Include & lt; Vector & gt; # Include & lt; Semith & gt; using namespace std; Structure frisbee (double x; Double wi; Double radius; }; Int DFS (Artificial vector & lt; vector & lt; int & gt; & amp; adj, vector & lt; int & amp;; p; int end_ind, int curr_ind) {if (P [curr_ind] ) // node has already been painted {if (p [last_ind] == p [curr_ind]) / / painted the same color as the neighbor - & gt; Failure Return 0; Return 1; // painting is compatible) // node has not yet been painted [curr_ind] = (1 == p [last_in] 2: 1); // Color for the neighborhood color (int j = 0; ed [curr_ind]. Size (); ++ J) if (! DFS (AD, P, CRR_ IND, ED [curr_ind]] [ J])) Return to neighbors // DF 0; Return 1; } Int divination (const vector & lt; frisbee & gt; f, vector & gt; int & gt; & amp; p) {// calculation adjacency list vector & lt; Of vector & lt; Int & gt; & Gt; Adj (f.size ()); P.resize (F.size ()); For (int i = 0; i
Here is the output (two partitions on a different set of Frisbee):
1 2 1 2 1 1 No division is possible!
No comments:
Post a Comment