Up: 1997 UMCP High School Programming Contest Previous: Heat Diffusion

# Ghosts and Ghostbusters

A group of n Ghostbusters is battling n ghosts. Each Ghostbuster is armed with a proton pack, which shoots a stream at a ghost, eradicating it. A stream goes in a straight line and terminates when it hits the ghost.

The Ghostbusters decide on the following strategy. They will pair off with the ghosts, forming n Ghostbuster-ghost pairs, and then simultaneously each Ghostbuster will shoot a stream at his or her ghost. As we all know, it is very dangerous to let streams cross, and so the Ghostbusters must choose pairings for which no streams will cross.

In other words, given the positions of the Ghostbusters and the ghosts, find a way to pair each Ghostbuster with each ghost so that the line segments joining each Ghostbuster to its ghost do not intersect.

Assume that the position of each Ghostbuster and each ghost is a fixed point in the plane and that no three positions are collinear (on the same line).

Hint: There exists a line passing through one Ghostbuster and one Ghost such that the number of Ghostbusters on one side of the line equals the number of ghosts on the same side.

## Input Format

The first line contains n, the number of ghosts/Ghostbusters. It is followed by the positions of n ghosts, then the positions of Ghostbusters, one on each line. A position consists of the X and Y coordinates, separated by a space. You may assume there are at most fifty pairs of ghosts and Ghostbusters.

## Output Format

First output the number of ghosts/Ghostbusters, then on each line output two positions corresponding to each pairing, with the coordinates separated by spaces.

Input: Output:
```2
5 5
3 2
6 3
4 1
```
```2
5 5   6 3
3 2   4 1
```

## Test data used in judging

There may be many right answers to a Ghostbusters problem. Therefore, the output is checked by a program .

## Our solution

Up: 1997 UMCP High School Programming Contest Previous: Heat Diffusion

Bill Pugh
Mon Mar 17 14:34:34 EST 1997