PROBLEM STATEMENT – Division 2, 300 Point Problem

advertisement
PROBLEM STATEMENT – Division 2, 300 Point Problem
Given a String input, you are to determine how many words within the String have 1, 2, 3, ..., 9, or 10 letters.
Always return an int[] of size 10. Arrange these quantities into an int[], such that element 0 of the return int[] contains the
number of words of length 1, and element 1 contains the number of words of length 2, etc.
DEFINITION
Class name: WordSize
Method name: numletters
Parameters: String
Returns: int[]
The method signature is (make sure it is declared public):
int[] numletters(String input);
input is a String of words separated by exactly one space
TopCoder will enforce the following restrictions:
* input will be between 1 and 50 characters in length, inclusive.
* input will contain only letters (A-Z, a-z) and spaces.
* no word in input will be longer than 10 letters.
* there will be exactly one space between words in input.
* input will have no leading or trailing spaces.
EXAMPLES
"this is a test" contains 1 word of length 1, 1 word of length 2, 0 words of length 3,
and 2 words of length 4. The return value is {1, 1, 0, 2, 0, 0, 0, 0, 0, 0}.
"Hello world a to two four three eighth seventh" contains:
1 word of length 1
1 word of length 2
1 word of length 3
1 word of length 4
3 words of length 5
1 word of length 6
1 word of length 7
The return value is {1, 1, 1, 1, 3, 1, 1, 0, 0, 0}
"the quick brown fox jumped over the lazy gray dogs" returns:
{0, 0, 3, 4, 2, 1, 0, 0, 0, 0}
"What is this world coming to" returns:
{0, 2, 0, 2, 1, 1, 0, 0, 0, 0}
PROBLEM STATEMENT – Division 2, 350 Point Problem
Given a list of movies containing a quantification of how much various people like them, and the number of people,
determine which movie is liked the most overall.
DEFINITION
Class name: Movies
Method name: mostLiked
Parameters: String[], int
Returns: String
The method signature is (make sure it is declared public):
String mostLiked(String[] movies, int people);
people represents the number of persons whose data is represented in movies.
Each String in movies contains the title of the movies followed by exactly one comma, followed by integers representing
how much each person likes that movie. Each movie is given in String format "<Title>,<int>,<int>,...,<int>"
Quotes, elipses, and angle brackets given for clarity only.
NOTES
- If multiple movies have the same maximum overall likeability, return the one that occurs first in the input String[].
TopCoder will enforce the following restrictions:
* Each integer in movies will be between -20 and 20, inclusive.
* people will be between 1 and 25, inclusive.
* The title of each movie will contain only letters, numbers, and spaces, and hyphens ('-').
* There will be exactly one integer for each person in each String in movies.
* There will be exactly one comma (and nothing else) between each integer, and between the movie title and the first
integer.
* There will be between 1 and 20 elements in movies, inclusive.
EXAMPLES
{“Terminated,2,5,3,6”,
“Legally Blunt,5,1,3,6”,
“Robocopper,1,0,6,2”,
“Abs of Steel,1,12,6,1”},
4
Terminated has a total of 2+5+3+6 = 16
Legally Blunt has a total of 5+1+3+6 = 15
Robocopper has a total of 1+0+6+2 = 9
Abs of Steel has a total of 1+12+6+1 = 20
Since Abs of Steel has the highest total, the method returns “Abs of Steel”.
Example #2:
{“Movie A,1,5”,
“B movie,2,1”,
“movie 3,6,0”,
“last one,-1,7”},
2
“Movie A”, “movie 3”, and “last one” all have overall likeability of 6, but “Movie A” occurs first, so the method returns “Movie
A”.
{“ ooidal,9,10,8,10”,” ooidal returns,10,8,10,6”,” ooidal strikes back,10,9,10,10”,”attack of the zoidals,10,10,10,10”}, 4
returns:
“attack of the zoidals”.
{“dok the admin,4,5,6,7,8,9,10”,”topcoder,10,-10,10,10,9,-8,7”,”mike lydon,0,10,-10,0,7,6,10”}, 7 returns:
“dok the admin”.
PROBLEM STATEMENT – Division 2, 1100 Point Problem/Division 1, 450 Point Problem
A group of supervisors at Acme Assembling, Inc., like to sleep in. However, they are still responsible for keeping up a
certain level of production at the factory. Since it is against union rules for an employee to work without a supervisor
present, this presents a conflict of interest. So, the supervisors have done some simple psychological analyses of their
employees, and know that, without a supervisor present, each individual has two factors which parameterize his behavior.
Each person has a certain time period which he will wait for a supervisor to come (patience factor), and a people factor,
which determines how many other people must leave before he does (follow-the-leader syndrome). Thus, in order to
continue their analyses and thus be able to maximize their sleeping-in habits, they've asked you to write a program to run
simulations of employee behavior, given each employee's parameters. Note that a person will leave based on whichever
condition is fulfilled first (patience or people).
DEFINITION
Class name: Employee
Method name: patience
Parameters: String[], int
Returns: int[]
The method signature is as follows (make sure it is declared public):
int[] patience (String[] employees, int supervisor);
Each String in employees will be of the format "<String>,<int>,<int>,<int>", which corresponds to "<NAME>,<STARTTIME>,<PATIENCE FACTOR>,<PEOPLE FACTOR>". (i.e., "John Smith,5,3,1"). There will be exactly one comma and no
space between the integers and between the name and the first integer. Quotes and angle brackets are included for clarity
only and will not be part of the String.
<START-TIME> is the hour at which the employee is scheduled to start work.
<PATIENCE FACTOR> is the number of hours the employee will wait for a supervisor to arrive before he leaves.
<PEOPLE FACTOR> is the number of people for whom the employee will wait to leave before he himself leaves. These
people must all leave on or after the time the employee arrives.
supervisor is the hour at which the supervisor comes in to the factory, allowing the employees to work.
The method should return an int[] of length 24, with each element containing the number of people that left at that hour.
i.e., index 0 of the return value corresponsds to 0 o'clock, index 1 corresponds to 1 o'clock, 12 corresponds to 12 o'clock, 13
corresponds to 13 o'clock, etc.
NOTES
- Everyone arriving at a particular time sees everyone who leaves at that time. Thus, if persons A and C arrive at 7 o'clock
and person B leaves at 7 o'clock, persons A and C see person B leaving. Similarly, if person A then leaves at 7 o'clock after
seeing person B leave, person C has seen 2 people leave.
- This problem is concerned with a single day only, starting at 0 o'clock and ending 24 hours later.
- Once a supervisor has arrived, he will stay until the end of the day.
- No one leaves on the hour on which the supervisor arrives.
- Employees may have identical names. This affects nothing.
TopCoder will enforce the following restrictions:
* employees will have between 1 and 50 elements, inclusive
* Each String in employees will be between 1 and 50 characters in length, inclusive
* The name of each employee will contain only letters (A-Z,a-z), numbers (0-9), spaces, and periods
* For each employee, <START-TIME> will be between 0 and 23, inclusive
* For each employee, <PATIENCE FACTOR> and <PEOPLE FACTOR> will be between 0 and 51, inclusive
* supervisor will be between 0 and 23, inclusive
EXAMPLES
{"Jane Doe,7,2,4",
"John Smith,8,3,2",
"Harry Hoser,8,1,1",
"Bob Lazy,8,0,0"}, 10
Prior to 7 o'clock, no one has come, thus no one has left. Jane Doe comes in to work at 7, and no supervisors are there.
However, she will wait for up to 2 hours or 4 people to leave, whichever comes first.
At 8 o'clock, the other three people arrive. Bob Lazy, having 0 patience and 0 people-factor, leaves immediately.
Seeing this, Harry Hoser, who has a people-factor of 1, has now seen 1 person leave, and he leaves himself (still at 8
o'clock).
Seeing this, John Smith has now seen 2 people leave, and leaves.
At 9 o'clock, Jane Doe has been waiting for 2 hours, and leaves.
When the supervisor arrives at 10 o'clock, no one is left. So, 3 people left at 8 o'clock, and 1 left at 9 o'clock.
The return value is: {0, 0, 0, 0, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}.
{"Oscar G. Rouch,3,4,3",
"W. T. Pooh,5,2,1",
"Dok,10,1,1",
"Zoidal,7,1,4",
"Chuck G. Nim,8,3,2"}, 9
Oscar comes in at 3.
W. T. Pooh comes in at 5. (Oscar has been waiting for 2 hours)
Zoidal comes in at 7. (Oscar has been waiting for 4 hours and leaves, so now W.T. Pooh has seen 1 person leave and
leaves).
Chuck G. Nim comes in at 8. (Zoidal now leaves, having waited for 1 hour).
Supervisor comes in at 9, and Chuck is still there.
Dok comes in at 10, and everything is kosher, because there is already a supervisor there.
So, 2 people left at 7, 1 person left at 8, and no one else left.
The return value is: {0, 0, 0, 0, 0, 0, 0, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
{"dok,8,0,0","Red man,7,1,5","Blue man,6,9,2","Green man,5,9,3","Chuck,4,9,4","gt494,3,9,5","Alexander,2,10,6"}, 9
returns:
{0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
{"Hard worker,0,23,1","Lazy person,5,0,51"}, 5 returns:
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
{"Hard worker,0,23,1","Lazy person,5,0,51"}, 6 returns:
{0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
PROBLEM STATEMENT – Division 1, 200 Point Problem
Every number has distinct factors. A square-free number is a number which has no factors other than 1 which are perfect
squares.
For example, 36 has factors: 1, 2, 3, 4, 6, 9, 12, 18, 36.
Of these, 4, 9, and 36 are perfect squares, therefore 36 is not squarefree.
Similarly, every number has what is called a square-free portion. The square-free portion of a number is simply the largest
square-free factor of that number. A number x is a factor of y, if when y is divided by x, the remainder is 0. In the case of
36,
36 has factors 1, 2, 3, 4, 6, 9, 12, 18, 36 and is not square-free.
18 has factors 1, 2, 3, 6, 9, and 18 and is not square-free.
12 has factors 1, 2, 3, 4, 6, and 12 and is not square-free.
9 has factors 1, 3, 9 and is not square-free.
6 has factors 1, 2, 3, 6 and is square-free.
Thus, the square-free portion of 36 is 6.
DEFINITION
Class name: Squarefree
Method name: squarefree
Parameters: int
Returns: int
The method signature is (make sure it is declared public):
int squarefree(int number);
Given a number, determine what its square-free portion is and return that number.
TopCoder will enforce the following restrictions:
* number will be between 1 and 1000000, inclusive.
EXAMPLES
squarefree(10) returns 10
squarefree(36) returns 6
squarefree(100) returns 10
squarefree(101) returns 101
squarefree(5460) returns 2730
PROBLEM STATEMENT – Division 1, 1100 Point Problem
We are familiar with the concept of a truth-table for a traditional boolean logic expression. Consider now extending that
concept into a trilean logic expression. Trilean logic, like boolean logic, has TRUE and FALSE values, but also has a third,
called MAYBE. The logic gates are as follows: AND, OR, XOR, NOT, INC
AND has two inputs and returns:
TRUE if all inputs evaluate to TRUE
FALSE if all inputs evaluate to FALSE
MAYBE otherwise
OR has two inputs and returns:
TRUE if at least one input evaluates to TRUE
FALSE if all inputs evaluates to FALSE
MAYBE otherwise
XOR has two inputs and returns (in order of precedence):
TRUE if exactly one input evaluates to TRUE
MAYBE if exactly one input evaluates to MAYBE
FALSE otherwise
NOT has one input and returns:
TRUE if input evaluates to FALSE
MAYBE if input evaluates to MAYBE
FALSE if input evaluates to TRUE
INC has one input and returns:
TRUE if input evaluates to MAYBE
MAYBE if input evaluates to FALSE
FALSE if input evaluates to TRUE
DEFINITION
Class name: Trilean
Method name: equivalent
Parameters: String[]
Returns: String[]
The method signature is as follows (make sure it is declared public):
String[] equivalent (String[] expressions);
Each String in expressions will contain a pre-fix notation trilean expression, such as: "AND NOT X1 OR X2 X3", where the
words "AND", "OR", "XOR", "NOT", and "INC" designate their respective logic gates, and "X<int>" designates an input to a
logic gate.
There may be multiple spaces between operators and operands in the expressions. You should deal with this.
Two trilean expressions are equivalent if they have identical truth-tables. That is, for every possible combination of inputs
(using all six possible inputs), both expressions produce identical output. Note that in order for two truth-tables do be
identical, they are not required to have the same number of inputs. For instance, "AND X1 NOT X1" evaluates to MAYBE for
any combination of inputs. Also, "AND AND X1 NOT X1 AND X2 NOT X2" always evaluates to MAYBE. Thus, these two
expressions ARE equivalent. However, "INC X1" and "INC X2" are not equivalent, since for the input X1 = TRUE, X2 =
MAYBE, "INC X1" evalutate to FALSE, and "INC X2" evaluates to TRUE.
Given a String[] of prefix notation expressions, determine which of them are equivalent, grouping the equivalencies
represented as "<int> <int> ... <int>" in Strings. Angle brackets, ellipses, and parentheses included for clarity only.
For instance, if we are given 5 expressions (0, 1, 2, 3, and 4), expressions 0, 2 and 3 are equivalent, and expressions 1 and
4 are equivalent, the correct return value is {"0 2 3", "1 4"}.
Each String in the return String[] must have the integers in ascending order, and the Strings must be sorted in ascending
order by the first integer in each String.
Thus, {"0 3 2", "1"} is not correct because the integers in the first String are not in ascending order, and {"1 2 3", "0"} is
not correct because the first integers of the Strings are not in ascending order.
NOTES
- Prefix notation is the idea of giving the operator first, followed by its operands, which in turn may be expressions
themselves. For instance, "AND AND AND X1 X2 AND X3 X4 AND X5 X6" in prefix notation is equivalent to "(((X1 AND X2)
AND (X3 AND X4)) AND (X5 AND X6))" in infix notation.
- The only valid X<int> inputs are X1, X2, X3, X4, X5, and X6.
TopCoder will enforce the following restrictions:
* expressions will contain between 1 and 50 elements, inclusive
* Each String in expressions will contain between 1 and 50 characters, inclusive
* Each String in expressions will be contain a correctly formatted prefix notation logic expression. That is, every input
requiring two inputs will have exactly two inputs, and every input requiring one input will have exactly one input. Also, there
will be no extra data in each String beyond what is required to define the logic expression.
* Each expression will have no more than the 6 distinct inputs X1, X2, X3, X4, X5, and X6.
Prefix notation is defined
EXAMPLES
expressions = {"OR X1 X2","AND NOT X1 X2"}
"OR X1 X2":
X1
X2
Result
FALSE FALSE FALSE
FALSE MAYBE MAYBE
FALSE TRUE
TRUE
MAYBE FALSE MAYBE
MAYBE MAYBE MAYBE
MAYBE TRUE
TRUE
TRUE
FALSE TRUE
TRUE
MAYBE TRUE
TRUE
TRUE
TRUE
"AND NOT X1 X2":
X1
X2
Result
FALSE FALSE MAYBE
FALSE MAYBE MAYBE
FALSE TRUE
TRUE
MAYBE FALSE MAYBE
MAYBE MAYBE MAYBE
MAYBE TRUE
MAYBE
TRUE
FALSE FALSE
TRUE
MAYBE MAYBE
TRUE
TRUE
MAYBE
These are not the same. Return value is {"0", "1"}.
expressions = {"NOT X1", "NOT X2"}
In order to justifiably compare these two truth tables, we must look at all possible inputs of X1 and X2
"NOT X1"
"NOT X2"
X1
X2
Result
X1
X2
Result
FALSE FALSE TRUE
FALSE FALSE TRUE
FALSE MAYBE TRUE
FALSE MAYBE MAYBE
FALSE TRUE
TRUE
FALSE TRUE
FALSE
MAYBE FALSE MAYBE
MAYBE FALSE TRUE
MAYBE MAYBE MAYBE
MAYBE MAYBE MAYBE
MAYBE TRUE
MAYBE
MAYBE TRUE
FALSE
TRUE
FALSE FALSE
TRUE
FALSE TRUE
TRUE
MAYBE FALSE
TRUE
MAYBE MAYBE
TRUE
TRUE
FALSE
TRUE
TRUE
FALSE
These clearly do not have the same result for every input. Return value is {"0","1"}.
expressions = {"AND X1 X2", "OR X1 NOT X2", "AND X2 X1"}
Expressions 0 and 2 have identical truth-tables and hence are equivalent, but expression 1 is different.
Return value is {"0 2", "1"}.
expressions = {"AND X1 NOT X1", "AND X2 NOT X2", "AND X3 NOT X3", "AND X1 X2", "NOT X3"}
Expressions 0, 1, and 2 are equivalent, 3 and 4 are distinct.
Return value is {"0 1 2", "3", "4"}.
expressions = {"XOR INC X1 NOT INC X2","NOT NOT INC INC NOT INC X2","INC INC INC INC INC NOT INC X2"}
Return value is {"0", "1 2"}.
Download