Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

The Battle of Hogwarts

The last battle of this age that the wizarding world will see is finally upon us. Hogwarts will soon be under siege by Voldemort and his Death Eaters. It is of utmost importance that the safety of the castle not be compromised, because Harry Potter is still on a secret mission assigned to him by Dumbledore. The professors of Hogwarts, powerful witches and wizards all, intend to seal the castle perimeters by casting protective enchantments ( Protego Horribilis). They plan to enclose the polygon shaped castle by a polygonal shield. But the professors are old, and magic is taxing. Therefore, the professors wish to create a polygonal shield with as few sides as possible, that completely encloses the polygonal boundaries of Hogwarts castle. But they must be wary, for there are Death Eaters lurking at specific locations around the castle. (Some might even have slunk inside, but lets not worry about them). To avoid certain doom, the shape of the shield must be such that all the Death Eaters are kept out, and none is contained between the shield and the castle. How many sides are there in the shield that the professors cast around the castle? Input Format N p1_x p1_y p2_x p2_y ... ... pN_x pN_y M q1_x q1_y q2_x q2_y ... ... qM_x qM_y Where: N is the no. of points (representing Death Eaters), and <pi_x,pi_y> is the i th point (accurate to 2 decimal places) . M is the no. of sides of the polygon Q (Hogwarts), and <qi_x, qi_y> are the vertices of the polygon Q. Output Format A single integer denoting the minimum number of sides of the protective shield polygon such that only the points within Hogwarts (Q) and the castle itself lies within the shield. Constraints N<=1000 M<=50 Sample Input #1

16 1.0 0.0 2.0 0.0 3.0 2.0 4.0 0.0 5.0 0.0 1.0 1.1 4.0 5.0 3.0 -1.0 0.0 0.0 0.5 1.75 0.75 3.0 1.5 4.5 2.75 3.5 3.0 2.5 1.75 2.75 3.0 1.0 4 1.5 1.5 2.0 1.0 3.5 1.5 2.25 3.0

Sample Output #1 3 Explanation: The Blue triangle encloses Hogwarts (green) without including any point apart from the lone Death Eater within the castle. Another example for clarity:

No triangle can include all the points within Hogwarts without including extra points from outside the castle (green polygon). As you can see visually the answer for this case is 4.

You might also like