Advertisement
xopsuei

costs

Dec 12th, 2012
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. /**
  2. * Gets the cost of a node, the difference between neighbours from the opposite side and the current side
  3. *
  4. * @param int u  the node to calculate it's cost
  5. *
  6. * @returns int  the cost of a node
  7. *
  8. */
  9. int get_cost(int u, vi& neighbours, vi& neighbours_position, vi& sides){
  10.     int side = sides[u];
  11.     int cost = 0;
  12.  
  13.     for(int i = neighbours_position[u]; i < neighbours_position[u + 1]; ++i){
  14.         if(side == sides[neighbours[i]]) --cost;
  15.         else ++cost;
  16.     }
  17.  
  18.     return cost;
  19. }
  20.  
  21. /**
  22. * Gets the cost of swapping two nodes in different sides, the difference between neighbours from the
  23. * opposite side and the current side
  24. *
  25. * @param int u   the first node
  26. * @param int v   the second node
  27. *
  28. * @returns int  the cost of swaping two nodes
  29. *
  30. */
  31. int get_cost(int u, int v, vi& neighbours, vi& neighbours_position, vi& sides){
  32.     return get_cost(u, neighbours, neighbours_position, sides) + get_cost(v, neighbours, neighbours_position, sides) - 2;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement