문제1545--FloorTiling

1545: FloorTiling

실행시간 제한: 1 Sec  메모리사용 제한: 128 MB
제출: 120  통과: 64
[제출] [채점기록] [묻고답하기]

문제 설명

You are tiling a floor that is width by height units. You are using strips of tile that are size by 1 units. The long side of the tiles should run along the side of the floor that is width units long. See the diagram for more details on exactly how the tiles should be placed.

Note how each row is offset by offset units from the one below it. (When thinking of how to offset the rows, imagine infinite horizontal strips of tiles.) Also, notice that the bottom row is touching the side. As the diagram illustrates, you will not be able to tile the whole floor with pieces that are size by 1.

입력 설명

The input consists of several data sets. The first line of the input file contains the number of data sets which is a positive integer.

Each data set consists of 4 integers. <size> <offset> <width> <height>

You can assume the following:

1. offset will be between 0 and size-1, inclusive.
2. size will be between 2 and floor(width/2), inclusive.
3. width and height will each be between 4 and 50, inclusive.

출력 설명

For each data set, print the area of the region that will not be covered when tiling according to the strategy shown in the image.

입력 예시 Copy

3
3 2 7 8
5 1 10 8
2 1 50 50

출력 예시 Copy

17
30
50

도움

* First data set is the example in the diagram above.