Contents
- 0 -
Contents
- 1 -
Contents
Chapter 1 Getting Started ............................... 1
Section 1.1 ............................................................... 1
1.1.1 Your Ride is Here .................................. 1
1.1.2 Greedy Gift Givers ................................ 2
1.1.3 Friday the Thirteenth ............................. 3
1.1.4 Broken Necklace ................................... 4
Section 1.2 ............................................................... 5
1.2.1 Milking Cows ....................................... 5
1.2.2 Transformations .................................... 5
1.2.3 Name That Number ............................... 6
1.2.4 Palindromic Squares ............................. 7
1.2.5 Dual Palindromes .................................. 7
Section 1.3 ............................................................... 8
1.3.1 Mixing Milk .......................................... 8
1.3.2 Barn Repair ........................................... 9
1.3.3 Calf Flac .............................................. 10
1.3.4 Prime Cryptarithm .............................. 10
Section 1.4 ............................................................. 11
1.4.1 Packing Rectangles ............................. 11
1.4.2 The Clocks .......................................... 12
1.4.3 Arithmetic Progressions ...................... 13
1.4.4 Mother's Milk ...................................... 13
Section 1.5 ............................................................. 14
1.5.1 Number Triangles ............................... 14
1.5.2 Prime Palindromes .............................. 14
1.5.3 Superprime Rib ................................... 15
1.5.4 Checker Challenge .............................. 16
Chapter 2 Bigger Challenges ......................... 17
Section 2.1 ............................................................. 17
2.1.1 The Castle ........................................... 17
2.1.2 Ordered Fractions................................ 18
2.1.3 Sorting a Three-Valued Sequence ....... 19
2.1.4 Healthy Holsteins ................................ 19
2.1.5 Hamming Codes ................................. 20
Section 2.2 ............................................................. 20
2.2.1 Preface Numbering ............................. 20
2.2.2 Subset Sums ........................................ 21
2.2.3 Runaround Numbers ........................... 22
2.2.4 Party Lamps ........................................ 23
Section 2.3 ............................................................. 24
2.3.1 Longest Prefix ..................................... 24
2.3.2 Cow Pedigrees .................................... 24
2.3.3 Zero Sum............................................. 25
2.3.4 Money Systems ................................... 25
2.3.5 Controlling Companies ....................... 26
Section 2.4 ............................................................. 27
2.4.1 The Tamworth Two ............................. 27
2.4.2 Overfencing ........................................ 28
2.4.3 Cow Tours ........................................... 29
2.4.4 Bessie Come Home ............................. 30
2.4.5 Fractions to Decimals ......................... 31
Chapter 3 Techniques more subtle................ 32
Section 3.1 ............................................................. 32
3.1.1 Agri-Net .............................................. 32
3.1.2 Score Inflation ..................................... 32
3.1.3 Humble Numbers ................................ 33
3.1.4 Shaping Regions .................................. 33
3.1.5 Contact ................................................ 34
3.1.6 Stamps ................................................. 35
Section 3.2 ............................................................. 36
3.2.1 Factorials ............................................. 36
3.2.2 Stringsobits .......................................... 37
3.2.3 Spinning Wheels ................................. 37
3.2.4 Feed Ratios .......................................... 38
3.2.5 Magic Squares ..................................... 38
3.2.6 Sweet Butter ........................................ 39
Section 3.3 ............................................................. 41
3.3.1 Riding the Fences ................................ 41
3.3.2 Shopping Offers .................................. 42
3.3.3 Camelot ............................................... 43
3.3.4 Home on the Range ............................. 44
3.3.5 A Game ................................................ 45
Section 3.4 ............................................................. 45
3.4.1 Closed Fences ...................................... 45
3.4.2 American Heritage .............................. 46
3.4.3 Electric Fences .................................... 47
3.4.4 Raucous Rockers ................................. 48
Chapter 4 Advanced algorithms and difficult
drills .................................................................... 49
Section 4.1 ............................................................. 49
4.1.1 Beef McNuggets .................................. 49
4.1.2 Fence Rails .......................................... 49
4.1.3 Fence Loops ........................................ 50
4.1.4 Cryptcowgraphy .................................. 52
Section 4.2 ............................................................. 52
4.2.1 Drainage Ditches ................................. 52
4.2.2 The Perfect Stall .................................. 53
4.2.3 Job Processing ..................................... 54
4.2.4 Cowcycles ........................................... 55
Section 4.3 ............................................................. 57
4.3.1 Buy Low, Buy Lower .......................... 57
4.3.2 The Primes .......................................... 57
4.3.3 Street Race ........................................... 58
4.3.4 Letter Game ......................................... 59
Section 4.4 ............................................................. 61
4.4.1 Shuttle Puzzle ........................................ 61
4.4.2 Pollutant Control ................................... 61
4.4.3 Frame Up ............................................... 62
Chapter 5 Serious Challenges ........................ 64
Section 5.1 ............................................................. 64
5.1.1 Fencing the Cows ................................ 64
5.1.2 Starry Night ......................................... 64
5.1.3 Musical Themes .................................. 66
Section 5.2 ............................................................. 67
5.2.1 Snail Trails .......................................... 67
5.2.2 Electric Fences .................................... 68
5.2.3 Wisconsin Squares .............................. 69
Section 5.3 ............................................................. 70
Contents
- 2 -
5.3.1 Milk Measuring ................................... 70
5.3.2 Window Area ...................................... 71
5.3.3 Network of Schools............................. 71
5.3.4 Big Barn .............................................. 72
Section 5.4 ............................................................. 73
5.4.1 All Latin Squares ................................ 73
5.4.2 Canada Tour ........................................ 73
5.4.3 Character Recognition ........................ 74
5.4.4 Betsy's Tour ......................................... 76
5.4.5 Telecowmunication ............................. 76
Section 5.5 ............................................................. 77
5.5.1 Picture ................................................. 77
5.5.2 Hidden Password ................................ 78
5.5.3 Towfive ............................................... 79
Chapter 6 Contest Practice ............................ 81
Section 6.1 ............................................................. 81
6.1.1 Postal Vans............................................. 81
6.1.2 A Rectangular Barn................................ 82
6.1.3 Cow XOR .............................................. 82
Appendices ......................................................... 84
Hints (use them carefully!) .................................. 84
Section 1.5.2 Prime Palindromes ................. 84
Section 1.5.4 Checker Challenge ................. 84
Section 3.1.4 Shaping Regions ..................... 85
Section 4.1.2 Fence Rails ............................. 85
Submitting Solutions ............................................ 86
Words..................................................................... 87
Chapter 1 Getting Started
- 1 -
Chapter 1 Getting Started
Section 1.1
1.1.1 Your Ride is Here
It is a well-known fact that behind every good comet is a UFO. These UFOs often come to collect loyal supporters from
here on Earth. Unfortunately, they only have room to pick up one group of followers on each trip. They do, however, let the
groups know ahead of time which will be picked up for each comet by a clever scheme: they pick a name for the comet
which, along with the name of the group, can be used to determine if it is a particular group's turn to go (who do you think
names the comets?). The details of the matching scheme are given below; your job is to write a program which takes the
names of a group and a comet and then determines whether the group should go with the UFO behind that comet.
Both the name of the group and the name of the comet are converted into a number in the following manner: the final
number is just the product of all the letters in the name, where "A" is 1 and "Z" is 26. For instance, the group "USACO"
would be 21 * 19 * 1 * 3 * 15 = 17955. If the group's number mod 47 is the same as the comet's number mod 47, then you
need to tell the group to get ready! (Remember that "a mod b" is the remainder left over after dividing a by b; 34 mod 10 is
4.)
Write a program which reads in the name of the comet and the name of the group and figures out whether according to the
above scheme the names are a match, printing "GO" if they match and "STAY" if not. The names of the groups and the
comets will be a string of capital letters with no spaces or punctuation, up to 6 characters long.
Examples:
Input
Output
COMETQ
HVNGAT
GO
ABSTAR
USACO
STAY
PROGRAM NAME: ride
This means that you fill in your header with:
PROG: ride
INPUT FORMAT
Line 1: An upper case character string of length 1..6 that is the name of the comet.
Line 2: An upper case character string of length 1..6 that is the name of the group.
NOTE: The input file has a newline at the end of each line but does not have a "return". Sometimes, programmers code for
the Windows paradigm of "return" followed by "newline"; don't do that! Use simple input routines like "readln" (for Pascal)
and, for C/C++, "fscanf" and "fid>>string".
SAMPLE INPUT (file ride.in)
COMETQ
HVNGAT
OUTPUT FORMAT
A single line containing either the word "GO" or the word "STAY".
SAMPLE OUTPUT (file ride.out)
GO