-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
💾 Feat: New USACO problems organized.
- Loading branch information
1 parent
116b8fd
commit ce43731
Showing
115 changed files
with
822 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,203 @@ | ||
GREEN PROBLEMS | ||
Four problems numbered 1 through 4 | ||
|
||
Problems - 2002 Winter Open, Green (Senior Division) | ||
|
||
# PROBLEM 1: Pasture Fences [Dominic Battre, 2001] | ||
|
||
Farmer John has a long fence made of fence poles and rails. Each of the N (1 <= N <= 3000) | ||
fence poles carries a sign with a single number from -1000 through +1000. Some poles might | ||
have the same number on their sign as other poles. While chewing their cud, the cows made up | ||
a game. The cow who can find the "best fence sum" gets ice cream for dessert. | ||
|
||
To win the game, the winning cow must find the longest contiguous set of poles whose sum has | ||
the smallest absolute value. Help them determine the winning sum. | ||
|
||
PROBLEM NAME: pasture | ||
|
||
## INPUT FORMAT: | ||
|
||
* Line 1: One line with a single integer: N | ||
|
||
* Lines 2..N+1: Each line contains a pole's label. Line 2 contains | ||
the value for pole with sequence number 1, etc. | ||
|
||
### SAMPLE INPUT (file pasture.in): | ||
|
||
```text | ||
6 | ||
5 | ||
10 | ||
-5 | ||
-6 | ||
2 | ||
4 | ||
``` | ||
|
||
## OUTPUT FORMAT: | ||
|
||
A single line with three numbers: | ||
* the sequence number of the pole that is first to be summed, | ||
* the sequence number of the pole that is last to be summed, and | ||
* the absolute value of the sum of the labels of those poles. If more than one | ||
sequence has the same "best fence sum" and same maximum length, report the sequence | ||
with the lowest first sequence number. | ||
|
||
### SAMPLE OUTPUT (file pasture.out): | ||
|
||
```text | ||
4 6 0 | ||
``` | ||
|
||
# PROBLEM 2: New Years Party [Hal Burch, 2001] | ||
|
||
A group of N (3 <= N <= 200) cows is having a New Year's party. Each cow is able | ||
to cook several different kinds of food (in units called a "dish"). There are a | ||
total of D (5 <= D <= 100) different kinds of food. Each kind of food is denoted | ||
by an integer in the range 1..D. | ||
|
||
The cowrdinator wants to maximize the total number of dishes brought to the party, | ||
but has specified a limit for the number of dishes of each type. Each cow can bring | ||
K (1 <= K <= 5) dishes, but they must be different from each other (she can't bring | ||
3 bovine pies, for example, but she could bring a pie, some bread, and some nice | ||
alfalfa in orange sauce). What is the maximum amount of food that can be brought? | ||
|
||
PROBLEM NAME: party | ||
|
||
## INPUT FORMAT: | ||
|
||
* Line 1: Three integers: N, K, and D | ||
|
||
* Line 2: D non-negative integers: the limit on total number of each of | ||
the various dishes that can be brought to the party | ||
|
||
* Lines 3..N+2: Each line contains an initial integer Z (1 <= Z <= D) | ||
denoting the number of different dishes a cow can prepare; the rest of | ||
the line contains Z integers that are the food identifiers, food type 1 | ||
first, food type 2 second, etc.. | ||
|
||
### SAMPLE INPUT [FILE party.in]: | ||
|
||
```text | ||
4 3 5 | ||
2 2 2 2 3 | ||
4 1 2 3 4 | ||
4 2 3 4 5 | ||
3 1 2 4 | ||
3 1 2 3 | ||
``` | ||
|
||
EXPLANATION OF SAMPLE INPUT: | ||
|
||
data...... explanation................................................... | ||
4 3 5 4 cows, each cow brings up to 3 dishes, 5 different food types | ||
2 2 2 2 3 max for party of 2 dishes food types 1..4; 3 dishes of food 5 | ||
4 1 2 3 4 This cow can cook 4 different foods (1, 2, 3, 4) | ||
4 2 3 4 5 This cow can cook 4 different foods (2, 3, 4, 5) | ||
3 1 2 4 This cow can cook 3 different foods (1, 2, 4) | ||
3 1 2 3 This cow can cook 3 different foods (1, 2, 3) | ||
|
||
## OUTPUT FORMAT: | ||
|
||
A single line with a single integer that is the maximum number of dishes that can | ||
be brought to the party. | ||
|
||
### SAMPLE OUTPUT [FILE party.out]: | ||
|
||
```text | ||
9 | ||
``` | ||
|
||
[Cow 1 brings foods 3 and 4; cow 2 brings foods 3, 4 and 5; | ||
cow 3 brings foods 1 and 2; and cow 4 brings foods 1 and 2.] | ||
|
||
|
||
# PROBLEM 3: Strolling Cows [Dan Adkins, 2001] | ||
|
||
Before going to the barn for dinner, the cows like to stroll the N (1 <= N <= 30,000) | ||
pastures while watching the sun set. Each pasture leads to precisely one pasture, though | ||
some pastures have more than one pasture emptying into them. For a valid strolling experience, | ||
the cows can start in any pasture and must finish in that same pasture without visiting any | ||
other pasture twice. Given a description of the pasture paths, deduce the longest possible | ||
valid stroll the cows can take. | ||
|
||
PROBLEM NAME: stroll | ||
|
||
## INPUT FORMAT: | ||
|
||
* Line 1: One integer: N | ||
|
||
* Lines 2..N+1: Line M tells the pasture number that pasture M-1 connects | ||
to (so line 2 tells which pasture is accessible from pasture 1, etc.) | ||
|
||
### SAMPLE INPUT (FILE stroll.in): | ||
|
||
```text | ||
5 | ||
2 | ||
4 | ||
5 | ||
5 | ||
2 | ||
``` | ||
|
||
## OUTPUT FORMAT: | ||
|
||
A single line with the integer that is the largest number of pastures that can be visited | ||
on a legal stroll. | ||
|
||
### SAMPLE OUTPUT (FILE stroll.out): | ||
|
||
```text | ||
3 | ||
``` | ||
|
||
[by visiting pasture 2, then 4, then 5] | ||
|
||
|
||
# PROBLEM 4: Grazing Sets [Brian Dean, 2001] | ||
|
||
Farmer John's N (4 <= N <= 10,000) cows live at various points within a circular field. | ||
FJ wants to partition his cows by building K (3 <= K <= 1000) fences radially outward | ||
from the center of the field at evenly-spaced angles (each measuring 360/K degrees). | ||
Depending on how he rotates this system of fences, he can partition the cows into K | ||
subsets, each containing a different subset of cows (potentially an empty subset). | ||
Define the RANGE of this partition as the number of cows in the largest set minus | ||
the number of cows in the smallest set. Determine the minimum attainable RANGE value | ||
for a given set of cows. | ||
|
||
Of course, no cow can straddle a fence. Cows must be in one partition or the other. | ||
|
||
To avoid problems with rounding, the input data will not contain cows that are very | ||
close to an integer multiple of 360/K degrees apart. | ||
|
||
PROBLEM NAME: grazeset | ||
|
||
## INPUT FORMAT: | ||
|
||
* Line 1: Two integers: N and K | ||
|
||
* Lines 2..N+1: Each line contains a single double that tells the angle at | ||
which a cow is grazing. Angles are expressed in degrees, 0 <= angle < | ||
360. | ||
|
||
### SAMPLE INPUT (FILE grazeset.in): | ||
|
||
```text | ||
4 3 | ||
30 | ||
60 | ||
150.003 | ||
240 | ||
``` | ||
|
||
## OUTPUT FORMAT: | ||
|
||
A single line with the integer that is the minimum attainable RANGE value | ||
for the set of cows. | ||
|
||
### SAMPLE OUTPUT (FILE grazeset.out): | ||
|
||
```text | ||
1 | ||
``` |
178 changes: 178 additions & 0 deletions
178
source/competitions/usaco/2002 January Silver/orange.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
ORANGE PROBLEMS | ||
Four problems numbered 5 through 8 | ||
|
||
# PROBLEM 5: Factorial Power [Piele, 1983] | ||
|
||
The factorial power of a whole number N is defined like this: | ||
|
||
N! = 1 * 2 * 3 * ... * N-1 * N | ||
|
||
For example, 12! = 1*2*3*4*5*6*7*8*9*10*11*12 = 479001600 | ||
|
||
The rightmost non-zero digit in 12! is 6; two zeroes follow it. | ||
Write a program that will compute the right-most non-zero digit | ||
in the decimal representation of N! and also find the number of | ||
zeroes after it. | ||
|
||
PROBLEM NAME: fact | ||
|
||
## INPUT FORMAT: | ||
|
||
One line with a single integer: N, 1 <= N <= 1,000,000 | ||
|
||
### SAMPLE INPUT (file fact.in): | ||
|
||
```text | ||
12 | ||
``` | ||
|
||
## OUTPUT FORMAT: | ||
A single line with two numbers: | ||
|
||
* The right most non-zero digit of N! | ||
* The number of zeroes that follow it | ||
|
||
### SAMPLE OUTPUT (file fact.out): | ||
|
||
```text | ||
6 2 | ||
``` | ||
|
||
# PROBLEM 6: Friday the Thirteenth [Traditional; Andree, 1965] | ||
|
||
Is Friday the 13th really an unusual event? | ||
|
||
That is, does the 13th of the month land on a Friday less often than on | ||
any other day of the week? To answer this question, write a program that | ||
will compute the frequency that the 13th of each month lands on Sunday, | ||
Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday over a given | ||
period of N years. The time period to test will be from January 1, 1900 | ||
to December 31, 1900+N-1 for a given number of years, N. N is non-negative | ||
and will not exceed 400. | ||
|
||
There are few facts you need to know before you can solve this | ||
problem: | ||
* January 1, 1900 was on a Monday. | ||
* Thirty days has September, April, June, and November, all the rest have | ||
31 except for February which has 28 except in leap years | ||
when it has 29. | ||
* Every year evenly divisible by 4 is a leap year (1992 = 4*498 so 1992 | ||
will be a leap year, but the year 1990 is not a leap year) | ||
* The rule above does not hold for century years. Century years divisible | ||
by 400 are leap years, all other are not. Thus, the century years 1700, | ||
1800, 1900 and 2100 are not leap years, but 2000 is a leap year. | ||
|
||
Do not use any built-in date functions in your computer language. | ||
|
||
Don't just precompute the answers, either. | ||
|
||
PROGRAM NAME: friday | ||
|
||
## INPUT FORMAT: | ||
|
||
One line with the integer N. | ||
|
||
### SAMPLE INPUT (file friday.in): | ||
|
||
```text | ||
20 | ||
``` | ||
|
||
## OUTPUT FORMAT: | ||
|
||
Seven space separated integers on one line. These integers represent the | ||
number of times the 13th falls on Saturday, Sunday, Monday, Tuesday, ..., Friday. | ||
|
||
### SAMPLE OUTPUT (file friday.out): | ||
|
||
```text | ||
36 33 34 33 35 35 34 | ||
``` | ||
|
||
# PROBLEM 7: Beef McNuggets [Hubert Chen, 1998] | ||
|
||
Farmer Brown's cows are up in arms, having heard that McDonalds is considering | ||
the introduction of a new product: Beef McNuggets. The cows are trying to find | ||
any possible way to put such a product in a negative light. | ||
|
||
One strategy the cows are pursuing is that of `inferior packaging'. ``Look,'' say | ||
the cows, ``if you have Beef McNuggets in boxes of 3, 6, and 10, you can not satisfy | ||
a customer who wants 1, 2, 4, 5, 7, 8, 11, 14, or 17 McNuggets. Bad packaging: bad product.'' | ||
|
||
Help the cows. Given N (the number of packaging options, 1 <= N <= 10), and a set | ||
of N positive integers (1 <= i <= 256) that represent the number of nuggets in the | ||
various packages, output the largest number of nuggets that can not be purchased by | ||
buying nuggets in the given sizes. Print 0 if all possible purchases can be made or | ||
if there is no bound to the largest number. | ||
|
||
The largest impossible number (if it exists) will be no larger than 2,000,000,000. | ||
|
||
PROGRAM NAME: nuggets | ||
|
||
## INPUT FORMAT: | ||
|
||
* Line 1: N, the number of packaging options | ||
|
||
* Line 2..N+1: The number of nuggets in one kind of box | ||
|
||
### SAMPLE INPUT (file nuggets.in) : | ||
|
||
```text | ||
3 | ||
3 | ||
6 | ||
10 | ||
``` | ||
|
||
## OUTPUT FORMAT: | ||
|
||
The output file should contain a single line containing a single integer that | ||
represents the largest number of nuggets that can not be represented or 0 if all | ||
possible purchases can be made or if there is no bound to the largest number. | ||
|
||
### SAMPLE OUTPUT (file nuggets.out): | ||
|
||
```text | ||
17 | ||
``` | ||
|
||
# PROBLEM 8: Calf Flac [Traditional; Brian Dean 2001] | ||
|
||
PROBLEM NAME: calfflac | ||
|
||
It is said that if you give an infinite number of cows an infinite number of | ||
heavy-duty laptops (with very large keys), that they will ultimately produce | ||
all the world's great palindromes. Your job will be to detect these bovine beauties. | ||
|
||
Ignore punctuation, whitespace, and case when testing for palindromes, but | ||
keep these extra characters around so that you can print them out as the | ||
answer; just consider the letters `A-Z' and `a-z'. | ||
|
||
Find any largest palindrome in a string no more than 20,000 characters long. | ||
The largest palindrome is guaranteed to be at most 2,000 characters long before | ||
whitespace and punctuation are removed. | ||
|
||
## INPUT FORMAT: | ||
|
||
A file with no more than 20,000 characters. | ||
|
||
### SAMPLE INPUT (file calfflac.in): | ||
|
||
```text | ||
Confucius say: Madam, I'm Adam. | ||
``` | ||
|
||
## OUTPUT FORMAT: | ||
|
||
The first line of the output should be the length of the longest palindrome found. | ||
The next line or lines should be the actual text of the palindrome (without any | ||
surrounding white space or punctuation but with all other characters) printed on a line | ||
(or more than one line if newlines are included in the palindromic text). If there are | ||
multiple palindromes of longest length, outputthe one that appears first. | ||
|
||
### SAMPLE OUTPUT (file calfflac.out): | ||
|
||
```text | ||
11 | ||
Madam, I'm Adam | ||
``` |
Oops, something went wrong.