Want to try solving this problem? You can submit your code online if you log in or register.

You are sitting at your computer, playing a peaceful game of Space Invaders. In this game, you control a cannon which you can move left and right along the bottom of a 2-dimensional grid. It fires vertically upwards and destroys whatever is in its line of fire. Above each square of the top row of the grid is a Space Invader, as shown in the diagram below.

After days of non-stop playing, you have reached the final level of the game. In this final level, large alien motherships occupy the grid to protect the Space Invaders. The motherships lie in between you and the Space Invaders and cannot be destroyed with your humble cannon. Your cannon can only destroy a Space Invader if a mothership is not obscuring its line of fire. The motherships are represented as large polygons with corners at integer coordinates. Before you attempt to win this battle, you need to determine how many Space Invaders you can now fire at.

For example, in the diagram below, there are only four Space Invaders which you can fire at directly. The others are obscured by the motherships.

Your task is, given the position and shapes of the motherships in the sky, to determine how many Space Invaders you can destroy using your cannon.

The first line of input will consist of two space-separated
integers *w h*, specifying the width and height of the area that the
motherships may occupy
(1 <= *w,h* <= 1,000,000,000).
The top-left corner of the grid is defined as coordinate (0,0).

The second line will consist of a single integer *k*, with
*0 <= k <= 100,000*,
specifying the number of motherships.

Following this will be the descriptions of each of the *k*
motherships represented as polygons. The *i*th of these definitions
will consist of a single integer *p_i*, the number of points in polygon
*i*, followed by *p_i* lines each containing a pair of integers
*x_j* and *y_j* separated by a single space
(0 <= *x_j* <= *w*,
0 <= *y_j* <= *h*).
Each of these pairs specifies one of the points on the boundary of
polygon *i*.

You are guaranteed that 3 <= *p_i* <= 10. No two
motherships may overlap, but their edges or corners may touch.

Your output should consist of a single integer--the total number of Space Invaders that you can destroy with the motherships in position.

10 4 4 3 8 2 9 2 8 3 4 3 0 4 0 4 2 3 1 5 5 0 6 0 7 1 7 2 6 2 5 1 0 2 0 3 2 2 2 1 1

4

11 9 3 3 7 0 10 3 6 1 4 3 5 3 9 4 5 4 9 5 6 7 7 6 7 8 8 6 8 7

6

The score for each input scenario will be 100% if the correct answer is written to the output file, and 0% otherwise.

Privacy
statement

© Australian Mathematics Trust 2001-2021

Page generated: 22 September 2021, 11:39am AEST