c++ - array to bipartite graph in a fastest way -


I have an array in the file input.txt, its elements are '*' and '.' It is possible. I have to make a bilateral graph from this. I have created the int array m to store the elements. Now I am reading the number of lines and the number of rows in lines, then I read lines 1 to 1 and int array m if I put 1 in the array '*' in line and -3 if I have '.' ' In this line again I go through the array M and connects all the corners (black and white) and then I go through the array again and all the elements Looks like, looks like mas [i] [j] (j) (i + j)% 2 == 1 I took one of these elements and see whether it was the neighbors (Element Mass [I-1] [J], Mess [I] [J-1], Mass [I] [J + 1], MAS [ I +1] [J] ). If this element gives me the vector & lt; Vector & lt; Int & gt; & Gt; G as ji [mas [i] [j]]. Push_back (neighboring) . If the elements are not neighbors, then I delete it (I do not need such elements in my problem) How can I improve the speed of this algorithm?

Here are some code:

  ifstream fin ("file"); Wings & gt; & Gt; P & gt; & Gt; K; Four s [k]; For (int i = 0; i & lt; p; ++ i) {Feather & gt; & Gt; S; For (int j = 0; j and lt; k; ++ j) {mas [ii] [j] = 43-s [j]; }} Fin.close (); (Int i = 0; i & lt; p; ++ i) {for (int j = 0; j & lt; k; ++ j) {if (mass [i] [j]> gt 1 = ) {If ((I-1)> = 0 and Mass [I-1] [J]> gt = = 0) || \ ((I + 1) & lt; p_heig & amp; mass [i + 1] [j]> = 0) || \ ((J-1)> gt; = 0 & amp; Mass [i] [j-1]> gt = = 0) || \ ((J + 1) & lt; m; m [i] [j + 1]> gt; = 0)) {if ((i_heig + j_wid)% 2 == 0} {mass [i] [j ] = Black; Black ++; } And {mas [ii] [j] = white; White ++; }} And {mas [ii] [j] = -1; Single ++; }}}}  


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -