Advertisement
updown

Untitled

Jan 23rd, 2023
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. 1. Create an arrayList of North cows, N_cows, and East cows E_cows
  2. 2. Find the collisions between north and east cows
  3.  
  4. array for the amount of grass each cow eats
  5.  
  6. loop N times
  7.  
  8. int collisionTime = infinity
  9. int cow1 = -1, cow2 = -1;
  10.  
  11. loop through N_cows:
  12. loop through E_cows:
  13. if they collide:
  14. if the collision time is less than collisionTime:
  15. update collisionTime, cow1, and cow2
  16.  
  17. if there is no collision:
  18. break;
  19.  
  20. // We have our collision!
  21. See if cow1 or cow2 stops
  22. Update the number of grass that cow eats for the output
  23. Remove the cow that stops from the arrayList
  24.  
  25.  
  26. // For printing our output
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement