All Ireland Schools Programming Competition

 

Day 1 Problems

There are three problems contained in this document. Attempt as many as you can.

Important

For each problem you must save your program as ‘dayNP.ext’ where N is the competition day (1 or 2), P is the particular problem (A, B, or C), and ext is the extension (BAS, BC, C, CPP or PAS). For example if you write a Pascal program to solve problem A on day 1 the name should be day1a.pas. Your program should read its input from a file called day1a.dat and write the solution to a file called day1a.sol.

With each problem are two examples. These examples will be used (in addition to other unseen tests) to test your program.

Note that if your program generates correct results for these test files, it does not mean that your program will give correct output for all possible input.

There is a batch file test.bat on the D: drive that will mark your program. If you type ‘test 1 a 1’, it will test day1a.exe or day1a.bas with example 1. So when you have written day1a, you can test it using the two example files that you are given using the commands

test 1 a 1

and

test 1 a 2

You can similarly test your programs, day1b and day1c.

When you are finished, ensure that you have saved your files onto the root directory of the I: drive. (That is, a BASIC program for problem A should be saved as I:\day1a.bas.) You will also be given a floppy disk at the end of the session, and you must also save your files to this disk and give it to a supervisor.

Best of luck

Note to BASIC users: if you want your program to be compiled you should save it as ‘day1a.bc’, otherwise you should save it as ‘day1a.bas’. To compile your program type ‘cbas day1a’ note that cbas day1a.bc won’t work.

Note that I:\ is equivalent to C:\test.

Problem 1A

Asterisk Rectangle

Description

Write a program to print a rectangle of asterisks given the width and height.

Input

The input contains two integers, l, (1 £ l £ 20), the length of the rectangle and h,

(1 £ h £ 20), the height of the rectangle.

Output

h lines of l asterisks.

Example 1

Input

5 3

Output

*****

*****

*****

Example 2

Input

8 2

Output

********

********

 

Problem 1B

Rotating Squares

Description

Imagine a square pattern divided into smaller squares as shown below

As you can see seven of the smaller squares are filled in. If this is rotated clockwise by 90° , and placed on top the original pattern then more squares are filled in.

original 90° rotation combination

Now the total number of filled in squares is thirteen. Continuing in this way you can again rotate and add the original pattern to the combination giving 19 black squares, and one more rotation + addition gives 25 black squares.

The four states are

You must write a program that will read in a square pattern and output the original number of black squares and the number that result from each rotation.

Input

The input will be an integer N (1 £ N £ 25) on a single line. The next N lines will consist of the N x N "square". In the square, a "1" represents a black square, and a "0" represents a white square.

Output

The output will be four lines each containing an integer. The first will be the number of black squares in the pattern. Each subsequent line will contain the result of a 90° rotation and addition to the pattern.

Example 1

Input

5

10100

10001

01100

01000

00000

Output

7

13

19

25

Example 2

Input

4

0000

0100

0010

0001

Output

3

6

7

8

 

 

 

 

 

Problem 1C

The King's Courtiers

Description

A king has a number of courtiers. Some courtiers have other courtiers as subordinates. And some of these subordinates have other subordinates. For example imagine there are nine courtiers and their relative status indicated by the following table

Courtier

 

has subordinates

1

 

7

 

7

 

5

8

5

 

3

 

9

 

1

 

2

 

3

 

From this table one can deduce the status of each courtier.










As you can see, courtiers 3, 8, 6 and 4 have no subordinates and thus have the lowest status. Next come 2 and 5, each with one subordinate, followed by 7, 1 and 9 each alone at their status.

The king pays his courtiers according to their status and needs to know how many courtiers of each status he has to pay. You have been summoned to write a program to do the job.

A word of warning: although there will be no circular references in the list of subordinates (e.g. courtier 3 could not say that 9 was a subordinate), there may be irrelevant relationships. E.g. 5 could be listed as a subordinate of 1 without changing the above result.

Input

The first line contains N, the number of courtiers (1 £ N £ 100). Then each courtier who has subordinates will have a line that contains the courtier number followed by a list of subordinates terminated by a -1. A courtier may have up to N-1 subordinates.

The list itself will also be terminated by -1.

Output

The output file will contain on each line the number of subordinates at each status starting at the lowest.

 

Example 1

Input

9

1 7 -1

7 5 8 -1

5 3 -1

9 1 -1

2 3 -1

-1

Output

4

2

1

1

1

Example 2

Input

4

2 1 3 4 –1

4 1 –1

-1

Output

2

1

1

 

Instructions for the Extra Problem

This problem will only be considered to distinguish between contestants whose scores are otherwise equal. You should ensure that you’ve got as many marks as possible in the other problems before attempting this one.

None of the test data will be seen, and there are no marks for producing an output file.

Otherwise this problem is the same as the others; you must save your program as ‘day1d.ext’ where ext is the extension (PAS, C, CPP or BC, BAS). Your program should read its input from a file called day1d.dat and write the solution to a file called day1d.sol.

Problem 1D

Sticky Gears

Description

An engineering firm needs a program which can evaluate the operation of gears on a board. The board is a two-dimensional mounting plane which allows gears with two levels of teeth (a lower radius closest to the board and an upper radius away from the board).

The gears rotate around the centre of their diameter and interact by turning an adjacent gear which it touches (either on the lower or upper radius) with an equal tangential velocity. Angular velocity is the same for both the lower and upper radius gears.

The mounting board is a 300 x 300 square grid of mounting holes. The lower left of the board is position x=1, y=1; the upper right of the board is position x=300, y=300. The gears mount only on mounting holes and are available with integer lower and upper radii between 1 and 100. The motor gear is the only original source of energy on the board and is powered from behind the board. The following diagram shows a sample configuration (see the first set of example data).

In the above example, the motor is at location x=20, y=100; the lower and upper radii of the gears the motor drives are both 5 centimetres, and the motor is rotating to the left (counter-clockwise) at 300 revolutions per minute (RPM). You can see that the motor touches (without overlapping) the lower radius of Gear #1. The lower radius of Gear #1 touches the lower radius of Gear #2 and Gear #3. The upper radius of Gear #3 touches the upper radius of Gear #4; the lower radius of Gear #4 touches the lower radius of Gear #5.

Given the data in the above example, it is possible to compute that Gear #1 rotates to the right (clockwise) at 83.33 RPM's; Gear #2 rotates to the left (counter-clockwise) at 187.50 RPM's; Gear #3 rotates to the left at 150.00 RPM's; Gear #4 rotates to the right at 281.25 RPM's; and Gear #5 rotates to the left at 33.75 RPM's.

Your program must identify two error conditions. The first error occurs when two or more gears would overlap at either the lower or upper radius. The second error condition occurs when any gear is being driven at two or more different speeds. It is valid for two or more gears to drive another gear at the same speed (and in the same direction).

It is possible for a warning condition to occur when 1 or more gears are idle (i.e. rotation = 0.0). If this condition occurs, your program will have to print a warning message as described below.

Input

Input to your program consists of an undetermined number of configurations to be analysed. Each set starts with a single line of six integers.

The first two integers are the x, y coordinates of the motor, 1 £ x £ 300, 1 £ y £ 300. The next two integers are the lower and upper radii of the motor gear respectively, each between 1 and 100. The fifth integer is the rotational velocity of the motor in RPM's (negative representing counter-clockwise rotation and positive representing clockwise rotation); the sixth integer is the number of gears, NG (1 £ NG £ 20) excluding the motor that are mounted on the board.

Each of the following NG lines contain exactly 4 integers representing gears 1 through NG respectively. The first two integers represent the x and, y coordinates of the gear and the second pair of integers represent the lower and upper radii of the gear respectively.

Output

Your program should print either a list of the gears and the rotation value for each or one of two error messages.

If there are no errors, each line either an 'L' for counter-clockwise rotation of the gear or a 'R' for clockwise rotation followed by a space, and the magnitude of the rotation always printed with two digits to the right of the decimal point. If any gear has rotation of magnitude zero, you should print the message "Warning - Idle Gear" instead of the rotation direction and magnitude.

If there is an overlapping of two or more gears at either in lower or upper radii, your program should print the message ``Error - Overlapping Gears". If there is any gear which is being driven by two or more different gears, your program should print the message ``Error - Conflicting Gear Rotation". Your program should give precedence to the overlapping error condition.

Example 1

Input

20 100 5 5 -300 5

43 100 18 10

43 74 8 4

71 100 10 15

94 100 3 8

122 100 25 6

Output

R 83.33

L 187.50

L 150.00

R 281.25

L 33.75

Example 2

Input

20 100 5 5 -300 5

43 100 18 10

43 74 8 4

71 100 10 15

92 100 3 8

105 100 25 6

Output

Error -- Overlapping Gears