• No results found

Problem A: Russian Dolls

N/A
N/A
Protected

Academic year: 2021

Share "Problem A: Russian Dolls"

Copied!
8
0
0

Loading.... (view fulltext now)

Full text

(1)

http://acm.uva.es/p/v105/10549.html

1 of 2 9/25/2003 1:22 PM

Problem A: Russian Dolls

Russian nesting dolls are brightly painted hollow wooden figures. The dolls in a set have roughly the same shape, typically humanoid, but different sizes. When the set is assembled, the biggest doll contains the second-biggest doll, the second-biggest contains the third-biggest, and so on.

We can approximate the shape of a doll as a cylinder of height h, diameter d, and wall thickness w. Such a doll would have a hollow of height h-2w and diameter d-2w.

Boris and Natasha each has a set of dolls. The sets are nearly identical; each has the same number of dolls, which look the same but differ in their dimensions. Last night Boris and Natasha were playing with their dolls and left them in the living room. Their mother tidied them away, dumping them all in one box. Can you help Boris and Natasha separate their sets of dolls?

Standard Input will consist of several test cases. The first line of each test case will contain n, the number of dolls in each set (1 < n <= 100). 2n lines follow; each gives the dimensions, h, d, w of a different doll (h,d >=

2w > 0). A line containing 0 follows the last test case.

For each test case, separate the dolls into two sets of nesting dolls such that, within each set, the dolls fit within each other, standing straight up, as described above. The first n lines of output should give the dimensions of the dolls in one set, in decreasing order by height. The next line should contain a single hyphen, "-". The next n lines should give the dimensions of the dolls in the second set, also in decreasing order by height. There will always be a solution. If there are many solutions, any will do. Output an empty line between test cases.

Sample Input

3100 100 3 97 97 3 94 94 3 91 91 3 88 88 3 85 85 3 5100 100 1 97 97 3 98 98 1 96 96 1 94 94 1 92 92 1 90 90 1 88 88 1 86 86 1 84 84 1 0

Possible Output

100 100 3 94 94 3 88 88 3

(2)

-97 97 3 91 91 3 85 85 3 100 100 1 98 98 1 96 96 1 94 94 1 92 92 1 -97 97 3 90 90 1 88 88 1 86 86 1 84 84 1

(3)

http://acm.uva.es/p/v105/10550.html

1 of 1 9/25/2003 1:21 PM

Problem B: Combination Lock

Now that you're back to school for another term, you need to remember how to work the combination lock on your locker. A common design is that of the Master Brand, shown at right. The lock has a dial with 40 calibration marks numbered 0 to 39. A combination consists of 3 of these numbers; for example: 15-25-8. To open the lock, the following steps are taken:

turn the dial clockwise 2 full turns

stop at the first number of the combination turn the dial counter-clockwise 1 full turn

continue turning counter-clockwise until the 2nd number is reached turn the dial clockwise again until the 3rd number is reached

pull the shank and the lock will open.

Given the initial position of the dial and the combination for the lock, how many degrees is the dial rotated in total (clockwise plus

counter-clockwise) in opening the lock?

Input consists of several test cases. For each case there is a line of input containing 4 numbers between 0 and 39. The first number is the position of the dial. The next three numbers are the combination. Consecutive numbers in the combination will be distinct. A line containing 0 0 0 0 follows the last case.

For each case, print a line with a single integer: the number of degrees that the dial must be turned to open the lock.

Sample Input

0 30 0 30 5 35 5 35 0 20 0 20 7 27 7 27 0 10 0 10 9 19 9 19 0 0 0 0

Output for Sample Input

13501350 16201620 18901890

G. V. Cormack

(4)

Problem C - Basic remains

Given a base b and two non-negative base b integers p and m, compute p mod m and print the result as a base b integer. p mod m is defined as the smallest non-negative integer k such that p = a*m + k for some integer a.

Input consists of a number of cases. Each case is represented by a line containing three unsigned integers.

The first, b, is a decimal number between 2 and 10. The second, p, contains up to 1000 digits between 0 and b-1. The third, m, contains up to 9 digits between 0 and b-1. The last case is followed by a line containing 0.

For each test case, print a line giving p mod m as a base-b integer.

Sample Input

2 1100 101

10 123456789123456789123456789 1000 0

Output for Sample Input

10789

P. Rudnicki

(5)

http://acm.uva.es/p/v105/10552.html

1 of 2 9/25/2003 1:23 PM

Problem D: Genealogical

Research

These days, everyone seems to be exploring their ancestry. This effort is supported by family history software, now marketed by a number of vendors. Unfortunately this software is expensive and runs only on the McDoze X operating system. You are to write an open-source equivalent.

Your program accepts a series of commands,

one per line. The commands are described by the following syntax:

command ::= birth ::= death ::= ancestors ::= descendants ::= QUIT

birth ::= BIRTH child: date: mother: father

death ::= DEATH person: date ancestors ::= ANCESTORS person descendants ::= DESCENDANTS person child ::= name

mother ::= name father ::= name person ::= name date ::= name

name ::= <<any sequence of characters not beginning or ending with a space or containing a colon>>

Spaces in the input are ignored except where they appear within name. The BIRTH and DEATH commands record the birth and death of an individual. You may assume that each individual has a unique name. The ANCESTORS and DESCENDANTS commands are queries: they print a family tree or a reverse family tree for the named person, using the BIRTH and DEATH information entered by previous commands. The QUIT command indicates the end of input.

The BIRTH, DEATH, and QUIT commands have no output. For each ANCESTORS (DESCENDANTS) command, print the following information:

1. Print a line containing "ANCESTORS of" ("DESCENDANTS of") followed by the person's name 2. Indented 2 spaces from the previous line, print the person's first parent (child) in alphabetical order, followed by the parent's (child's) birth date, followed by a space, followed by a hyphen, and, if the parent (child) has died, another space and the date of death. If there is no birth record for the parent (child), print the name alone.

3. Print the ancestry (descendant) information for the parent (child), indented another 2 spaces, using these same steps (i.e. steps 2-4).

(6)

4. Repeat steps 2-4 for the remaining parent (children). Indentation should be the same as for the previous parent (child).

Leave an empty line between the output sequences for successive commands.

You may assume that no input line exceeds 100 characters, and that there are not more than 250 lines of input. You may assume that DEATH, ANCESTORS, and DESCENDANTS commands refer to a name for which a BIRTH command has previously been given. QUIT appears only as the last line of input.

Sample Input

BIRTH John Doe : January 7, 1599 : Jane Doe : Adam Doe BIRTH Mary Worth : May 18, 1666 : Jane Doe : Adam Doe BIRTH Casper Ghost : Jan 2, 1959 : Mary Worth : John Doe DEATH Mary Worth : Jan 3, 1959

ANCESTORS Casper Ghost DESCENDANTS John Doe QUIT

Output for Sample Input

ANCESTORS of Casper Ghost John Doe January 7, 1599 - Adam Doe

Jane Doe

Mary Worth May 18, 1666 - Jan 3, 1959 Adam Doe

Jane Doe

DESCENDANTS of John Doe Casper Ghost Jan 2, 1959 -

G. V. Cormack

(7)

http://acm.uva.es/p/v105/10553.html

1 of 2 9/25/2003 1:23 PM

Problem E: Treasure Map

You have come into possession of a pirate map that gives a series of steps to get from your landing place on a desert isle to the spot marked X where the treasure is located. Each step consists of a compass heading and a number of paces.

After spending most of your savings chartering a boat, you arrive at the island and, with the help of your portable GPS receiver, duly execute the instructions on the map. Alas, no treasure! On your return home you are astonished to learn that the pirates had no knowledge of GPS and used a magnetic compass to create the map.

The pirates were unaware that their compass pointed to magnetic north rather than true north. The relative angle between magnetic north and true north varies depending

where you are on the planet, but you are able to determine that on this particular desert isle, magnetic north is d degrees from true north. How close were you to the spot marked X at any moment while following the map?

There are several test cases. Each test case begins with n <= 1000, the number of steps in the map. n lines follow; each consists of one of the 32 named compass points shown at right followed by a number of paces.

The last line is a number giving the angle between magnetic north and true north, in degrees. A positive number indicates that magnetic north is to the east of true north; a negative indicates that it is to the west.

The magnitude of this angle will not exceed 90 degrees. A line containing 0 follows the input for the last case.

For each test case, output a single number, rounded to two decimal places, giving the least distance (in paces) that separated you from the treasure at any point while you were following the map.

Note: We use combinations of the letters N,E,S,W,b to abbreviate the names of the compass points. For example, NEbE stands for north-east by east. The 32 points are equally spaced about the compass.

Clockwise, they are: N NbE NNE NEbN NE NEbE ENE EbN E EbS ESE SEbE SE SEbS SSE SbE S SbW SSW SWbS SW SWbW WSW WbS W WbN WNW NWbW NW NWbN NNW NbW.

Sample Input

2NbE 10 EbS 10 90.00 2NbE 10 EbS 10 -90.00 0

Output for Sample Input

14.14 10.00

(8)

G. V. Cormack

References

Related documents

Results presented here (Table 1, Table 2) suggest that the bacterial communities associated with Tuber magnatum ascomata, including Sphin- gobium sp., could contribute

• Access leads from DocuHome’s Referral Network • Exclusive marketing collateral (online and offline) • We provide your customers 24/7/365 support • Work directly with our

The apparent fathers (husbands) who took legal proceedings in the constitutional litigation were suffering under their unsettled legal status. In addition to this Article 847,

A) There is evidence of need for Psychology: a study made last year revealed that among 37 different majors pursued by premedical students, psychology was fourth. B)

Adam4adam.com. In doing this, another goal is to explore the parameters of sexual racism theory and their impact on sexual health behaviors and negotiations. Sexual Racism

Die logica is: (a) Niet mijn wil, maar uw wil geschiede; (b) als de vorst iets doet dat tegen de geopen- baarde wil van God ingaat is terrorisme geoorloofd; (c) wie de wil

The present study investigated the suicidal ideation rate and odds ratio of callers under 20 years of age (N = 24,333) with family problems to the Japanese crisis hotline in 2012..

Aquí només consten nominal- PHQWVLVEHQHÀFLDULVWRWLTXHKRPSUHYHXTXHV·HVWDEOHL[LQÀQVDGRVFHQWVOODXUDGRUVUHVL- dents (laboratores), d’acord amb les assignacions que