Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Problem 1: Perfection

From the article Number Theory in the 1994 Microsoft Encarta: "If A, B, C are integers such that A=BC, A is called a multiple of B or of C, and B or C is called a divisor or factor of A. If C is not 1, B is called a proper divisor of A. Even integers, which include 0, are multiples of 2, for example, -4, 0, 2, 10; an odd integer is an integer that is not even, for example, -5, 1, 3, 9. A perfect number is a positive integer that is equal to the sum of all its positive, proper divisors; for example, 6, which equals 1 + 2 + 3, and 28, which equals 1 + 2 + 4 + 7 + 14, are perfect numbers. A positive number that is not perfect is imperfect and is deficient or abundant according to whether the sum of its positive, proper divisors is smaller or larger than the number itself. Thus, 9, with proper divisors 1, 3, is deficient; 12, with proper divisors 1, 2, 3, 4, 6, is abundant." Problem Statement: Given a number, determine if it is perfect, abundant, or deficient. Input A list of n positive integers (none greater than 60,000), with 1 < n < 100. A 0 will mark the end of the list. Sample Input 15 28 6 56 60000 22 496 0 Output for Sample Input 15 deficient 28 perfect 6 perfect 56 abundant 60000 abundant 22 deficient 496 perfect

Problem 2: Intersecting Lines


We all know that a pair of distinct points on a plane defines a line and that a pair of lines on a plane will intersect in one of three ways: 1) No intersection because they are parallel. 2) Intersect in a line because they are on top of one another (i.e. they are the same line). 3) Intersect in a point. In this problem you will use your algebraic knowledge to create a program that determines how and where two lines intersect. Your program will repeatedly read in four points that define two lines in the x-y plane and determine how and where the lines intersect. All numbers required by this problem will be reasonable, say between -1000 and 1000. Input The first line contains an integer N between 1 and 10 describing how many pairs of lines are represented. The next N lines will each contain eight integers. These integers represent the coordinates of four points on the plane in the order x1 y1 x2 y2 x3 y3 x4 y4. Thus each of these input lines represents two lines on the plane: the line through (x1, y1) and (x2, y2) and the line through (x3, y3) and (x4,y4). The point (x1, y1) is always distinct from (x2, y2). Likewise with (x3, y3) and (x4, y4). Sample Input 5 0 5 5 2 0

0 0 0 0 3

4 7 7 2 4

40440 61023 6 3 -6 4 -3 27 1 5 18 5 01225

Output There should be N+2 lines of output. The first line of output should read INTERSECTING LINES OUTPUT. There will then be one line of output for each pair of planar lines represented by a line of input, describing how the lines intersect: none, line, or point. If the intersection is a point then your program should output the x and y coordinates of the point, correct to two decimal places. The final line of output should read "END OF OUTPUT". Output for Sample Input INTERSECTING LINES OUTPUT point 2.00 2.00 none line point 2.00 5.00 point 1.07 2.20 END OF OUTPUT

Problem 3: Gleaming the Cubes


As chief engineer of the Starship Interprize, the task of repairing the hyperstellar, cubic, transwarpedout software has fallen on your shoulders. Simply put, you must compute the volume of the intersection of anywhere from 2 to 1000 cubes. Input The input data file consists of several sets of cubes for which the volume of their intersections must be computed. The first line of the data file contains a number (from 2 to 1000) which indicates the number of cubes which follow, one cube per line. Each line which describes a cube contains four integers. The first three integers are the x, y, and z coordinates of the corner of a cube, and the fourth integer is the positive distance which the cube extends in each of the three directions (parallel to the x, y, and z axes) from that corner. Following the data for the first set of cubes will be a number which indicates how many cubes are in a second set, followed by the cube descriptions for the second set, again one per line. Following this will be a third set, and so on. Your program should continue to process sets of cubes, outputting the volume of their intersections to the output file, one set per line, until a zero is read for the number of cubes. Note that the data file will always contain at least one set of cubes, and every set will contain at least 2 and at most 1000 cubes. For any given set of cubes, the volume of their intersections will not exceed 1,000,000 units. Sample Input 2 0 9 3 0 9 8 0

0 0 10 115 0 0 10 115 223

Output for Sample Input 25 9

Problem 4: Jelly
A local school provides jelly for their pupils every day, and the school staff are very careful to see that each child has exactly the same amount. The jelly is prepared the previous day; the liquid jelly is poured into rectangular sided moulds, one mould per child, and then put in the fridge where it sets. The moulds may differ by the length and width of their sides but are filled to different heights so that they all have the same volume; length, width, and height are always integer numbers. Unfortunately, one of the cleaners loves practical jokes! Whenever he can, before the jelly has set, he tips liquid jelly from one of the moulds into another. He is happy if he succeeds just once and doesnt repeat the joke with other moulds. Your task is to help the school staff by preparing a report for them. They need to know who has lost jelly and who has gained it so that they can correct matters before the children arrive. Input The input consists of one or more scenarios. Each scenario begins with a single integer n, 1 n 100, representing the number of children for whom jelly was prepared. Following this are n lines, each line representing one child. The data for a child consists of the childs name and 3 integer numbers in the range 1 to 100, respectively representing the length, width and height of the jelly in that childs mould, all separated by single spaces. A childs name consists of a sequence of 1 up to 10 letters (upper and/or lower case), and no two children have the same name. A single 0 on a line by itself marks the end of input. Sample Input 3 Joe 10 10 2 Susan 10 5 4 Bill 5 5 8 4 Zoe 10 2 2 Lee 6 5 2 Alan 5 4 4 Tommy 12 5 1 0 Output Your report consists of one line of text per scenario. If the cleaner did not manage to transfer any jelly before it set, you report must say: No child has lost jelly; if the cleaner did manage to transfer jelly, your report must be of the form: ChildA has lost jelly to ChildB, where ChildA is the actual name of the child that has lost jelly and ChildB is the actual name of the child that has gained jelly. Output for Sample Input No child has lost jelly Zoe has lost jelly to Alan

Problem 5: Crossing a Dessert


You will compute how much food you need to purchase for a trip across the desert on foot. At your starting location, you can purchase food at the general store and you can collect an unlimited amount of free water. The desert may contain oases at various locations. At each oasis, you can collect as much water as you like and you can store food for later use, but you cannot purchase any additional food. You can also store food for later use at the starting location. You will be given the coordinates of the starting location, all the oases, and your destination in a two-dimensional coordinate system where the unit distance is one mile. For each mile walked, you must consume 1 unit of food and 1 unit of water. Assume that these supplies are consumed continuously, so if you walk for a partial mile you will consume partial units of food and water. You are not able to walk at all unless you have supplies of both food and water. You must consume the supplies while you are walking, not while you are resting at an oasis. There is a limit to the total amount of food and water that you can carry. At no time can the sum of the food units and the water units that you are carrying exceed this capacity. You must decide how much food you need to purchase at the starting location in order to make it to the destination. You need not have any food or water left when you arrive at the destination. Since the general store sells food only in whole units and has only one million food units available, the amount of food you should buy will be an integer greater than zero and less than or equal to one million. Input The first line of input in each trial data set contains n (2 n 20), which is the total number of significant locations in the desert, followed by an integer that is your total carrying capacity in units of food and water. The next n lines contain pairs of integers that represent the coordinates of the n significant locations. The first significant location is the starting point, where your food supply must be purchased; the last significant location is the destination; and the intervening significant locations (if any) are oases. You need not visit any oasis unless you find it helpful in reaching your destination, and you need not visit the oases in any particular order. The input is terminated by a pair of zeroes. Sample Input 4 100 10 -20 -10 5 30 15 15 35 2 100 00 100 100 00 Output For each trial, print the trial number followed by an integer that represents the number of units of food needed for your journey. Use the format shown in the example. If you cannot make it to the destination under the given conditions, print the trial number followed by the word "Impossible." Place a blank line after the output of each test case. Output for Sample Input Trial 1: 136 units of food Trial 2: Impossible

Problem 6: James Bond


A terrorist hides in an underground sewage system. Any two pipes have at most one common node that is also an endpoint for both of them. The terrorist hides in one such node and has placed clockactivated bombs at several other nodes. The passage into and through a node becomes impossible after the explosion. James Bond wants to capture this terrorist and has at his disposal a complete map of the sewage system that also highlights the position of the terrorist, the placement of the bombs, and their timings. At time 0 Bond starts from one of the nodes and must reach the terrorist in the shortest possible time. All pipes are bi-directional, at least for Bond. He can travel both ways with the same speed. Bond dies if an explosion catches him in one of the trapped node, but otherwise he is unscathed and can pursue his search (even if he is just one second away from the blast). Determine the minimum time that Bonds needs to capture the terrorist, if this is possible. Input Line 1: four positive integers N, M, S, T. N is the number of nodes and nodes are numbered 1, 2,N. M is the number of pipes. There is at most one pipe between each pair of nodes. S is Bonds starting node, and T is the node where the terrorist hides (1 S, T N 100, 1 M N2). Next N Lines: Each line contains 0 if the corresponding node is not trapped. Otherwise it contains a positive integer X giving the time when the bomb will detonate (1 X 1000). Next M Lines: Each line contains two node numbers representing the pipes end nodes, and a positive integer giving the travel time Y between its end nodes (1 Y 1000). The above set can be repeated several times. The end is signaled by a line with N=M=S=T=0. Sample Input 4 0 0 5 0 2 3 3 1 3 0 1 0 1 2 0 414

1 4 2 3 2

3 4 2 4 13

23 31 000

Output Print one line for each input set, giving the minimum time that Bonds needs to capture the terrorist, if this is possible (thus print 0 if Bond starts at the terrorist node). Otherwise print 0. Output for the Sample Input 8 0

Problem 7: Theseus and the Minotaur


Those of you with a classical education may remember the legend of Theseus and the Minotaur. This is an unlikely tale involving a bull headed monster, an underground maze full of twisty little passages all alike, love-lorn damsels and balls of silk. In line with the educational nature of this contest, we will now reveal the true story. The maze was actually a series of caverns connected by reasonably straight passages, some of which could only be traversed in one direction. In order to trap the Minotaur, Theseus smuggled a large supply of candles into the Labyrinth, as he had discovered that the Minotaur was afraid of light. Theseus wandered around somewhat aimlessly until he heard the Minotaur approaching along a tunnel. At this point he lit a candle and set off in pursuit. The Minotaur retreated into the cavern it had just left and fled by another passage. Theseus followed, slowly gaining, until he reached the k'th cavern since lighting the candle. Here he had enough time to place the lighted candle in the middle of the cavern, light another one from it, and continue the chase. As the chase progressed, a candle was left in each k'th cavern passed through, thereby limiting the movement of the Minotaur. Whenever the Minotaur entered a cavern, it would check the exits in a particular order, fleeing down the first that did not lead directly to a lit cavern. (Remember that as Theseus was carrying a lit candle, the Minotaur never exited a cavern by the tunnel used to enter it.) Eventually the Minotaur became trapped, enabling Theseus to defeat it. Consider the following Labyrinth as an example, where in this case the Minotaur checks the exits from a cavern in alphabetical order:

Assume that Theseus is in cavern C when he hears the Minotaur approaching from A, and that for this scenario, the value of k is 3. He lights a candle and gives chase, pursuing it through A, B, D (leaves a candle), G, E, F (another candle), H, E, G (another), H, E (trapped). Write a program that will simulate Theseus's pursuit of the Minotaur. The description of a labyrinth will identify each cavern by an upper case character and will list the caverns reachable from that cavern in the order that the Minotaur will attempt them, followed by the identifiers for the caverns which the Minotaur and Theseus were in when contact was first made, followed by the value of k. Write a program that will simulate Theseus' pursuit of the Minotaur. Input Input will consist of a series of labyrinths. Each labyrinth will contain a series of cavern descriptors, one per line. Each line will contain a cavern identifier (a single upper case character) followed by a colon (:) and a list of caverns reachable from it (in counterclockwise order). No cavern will be connected to itself. The cavern descriptors will not be ordered in any way. The description of a labyrinth will be terminated by a line starting with a @ character, followed by two pairs of cavern identifiers. The first pair indicates the passage in which Theseus starts, and the second in which the Minotaur starts. The travel in a starting passage is toward the cavern whose identifier is the second character in the pair.

Theseus and Minotaur will never start in the same corridor. The file will be terminated by a line consisting of a single #. A final encounter is possible for each input data set. Sample Input A:BCD D:BACG F:HE G:HED B:AD E:FGH H:FEG C:AD @ACFH A:BCD D:BACG F:HE G:HED B:AD E:FGH H:FEG C:AD @ACDG # Output Output will consist of one line for each labyrinth. Each line will specify who gets killed and where. Note that if the final encounter takes place in a passage it should be specified from Theseus' point of view. Follow the format shown in the example below exactly, which describes the situations referred to above. Output for the Sample Input Theseus is killed between D and G The Minotaur is slain in H

You might also like