10902 - Moving Cars (barriers)   

Description

Given the position of N cars and M barriers on a map, we have to list the valid moves of each car along 4 directions (i.e. right, down, left and up).

The width of a car must be 1, the length is between 2 and 9.

If the row of the tail of a car is the same as the row of the head, then the car is a horizontal car. Similarly, if the column of the tail of a car is the same as the column of the head, then the car is a vertical car.

Note that horizontal cars can only move horizontally, vertical cars can only move vertically.

A car must stop when it encounters a barriers (i.e. the character ‘#’ in the map).

For example, a map with 10 cars and 4 barriers is shown below:

Given the coordinate of car 2 is 1 3 1 6, it means car 2 occupies the position of (1,3) to (1,6) in the map. Car 2 can only move horizontally since the row of its tail and head are both 1.

The valid moves of car 2 is 1 0 1 0, which means it can move right 1 grid, can’t move down, can move left 1 grid and can’t move up.

 

Note that

1.      This problem involves three files.

  • function.h: Function definition of list_moves.
  • function.c: Function implementation of list_moves.
  • main.c: A driver program to test your implementation.

You will be provided with main.c and function.h, and asked to implement function.c.

2.     For OJ submission:

       Step 1. Submit only your function.c into the submission block. (Please choose c compiler) 

       Step 2. Check the results and debug your program if necessary.

Hint

function.h

main.c

 

Input

The first line has two integer N and M (1<=N,M<=10), which means the total number of cars and total number of barriers.

The following N lines are the coordinates of all cars.

Each line consists of 4 numbers. The first two numbers are the row and column of the head of the car. The other two numbers are the row and column of the tail of the car.

The following M lines are the coordinates of all barriers.

Each line consists of 2 numbers, which are the row and column of the barrier.

Output

Print out the valid moves of the cars in each line.

Each line consists of 4 number, the valid moves along right, down, left and up.

All of the numbers in the same line are separated by a space, and there is a '\n' at the end of each line.

Sample Input  Download

Sample Output  Download

Partial Judge Code

10902.c

Partial Judge Header

10902.h

Tags

10401Final



Discuss