Problem 2398. FIFA World Cup 2014 : Offside
This problem is about offside rule in football (soccer).
Input is a matrix with mostly zeros and a few 1, 2, 3 and 4s. A zero indicates empty space in the field. A 1 indicates a player from team A. A 3 indicates a player from team B. A 2 indicates a player from team A who is in possession of the ball. A 4 indicates a player from team B who is in possession of the ball. Players on the top and bottom rows indicate the goalkeepers of two teams. Determine if there is any player from either team who is in offside position and return true if yes. Complicated scenarios such as offside rule during passes or crosses are not considered (will be in the next problem). Someone will always be in possession of the ball.
Definition of offside (for the sake of this problem): Closest player (without having possession of the ball) to a goalkeeper must be from the same team of the goalkeeper.
Example:
input:
x=[0 0 0 1 0 0 0; 0 0 0 3 0 0 0; 0 0 0 2 1 0 0; 0 0 0 3 1 3 1; 0 3 1 0 1 0 1; 0 1 3 1 3 1 3; 0 3 0 0 0 0 0; 0 0 3 0 0 3 0; 0 0 0 3 0 0 0];
Output : True
Player of team B in the second row is closer to the goal keeper of team A than any other defenders of team A and the ball is currently at the third row. So, it is offside and thus true.
Solution Stats
Problem Comments
-
2 Comments
In test case 3, the closest players to goalie 1 are all 3's--aren't they offside?
Thanks for pointing it out :-).. Corrected that. In reality, it wont be offside, since team 1 is in attack. However, I found it kind of difficult to define one team being in attack. So, corrected it anyway.
Solution Comments
Show commentsProblem Recent Solvers14
Suggested Problems
-
2576 Solvers
-
5577 Solvers
-
358 Solvers
-
344 Solvers
-
774 Solvers
More from this Author44
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!