Login Register


CCC Junior 2016 [challenges] filter_list
Author
Message
CCC Junior 2016 [challenges] #1
I wrote CCC on Wednesday and got a perfect score, so I'm interested to see how you guys do. Unfortunately, the test cases aren't yet publically available, so I'll supply a few for each.

Spoiler: j1 - Tournament Selection
Problem Description:
Each player in a tournament plays six games. There are no ties. The tournament director places the players in groups based on the results of games as follows:
  • if a player wins 5 or 6 games, they are placed in group 1
  • if a player wins 3 or 4 games, they are placed in group 2
  • if a player wins 1 or 2 games, they are placed in group 3
  • if a player does not win any games, they are eliminated from the tournament

Input Specification:
The input consists of six lines, each with one of two possible letters: "W" (to indicate a win) or "L" (to indicate a loss).

Output Specification:
The output will be either 1, 2, 3 (to indicate which group the player should be placed in) or -1 (to indicate the player has been eliminated).


Sample 1:
In:
Code:
W L W W L W

Out:
Code:
2

Sample 2:
In:
Code:
L L L L L L

Out:
Code:
-1

Spoiler: j2 - Magic Squares
Problem Description:
Magic Squares are square arrays of numbers that have the interesting property that the numbers in each column, and in each row, all add up to the same total.

Input Specification:
The input consists of four lines, each line having 4 space-separated integers.

Output Specification:
Output either "magic" if the input is a magic square, or "not magic" if the input is not a magic square.

Sample 1:
In:
Code:
16 3 2 13 5 10 11 8 9 6 7 12 4 15 14 1

Out:
Code:
magic

Sample 2:
In:
Code:
5 10 1 3 10 4 2 3 1 2 8 5 3 3 5 0

Out:
Code:
not magic

Spoiler: j3 - Hidden Palindrome
Problem Description:
A palindrome is a word which is the same when read forwards as it is when read backwards. For example, "mom" and "anna" are two possibilities.

Input Specification:
The input will consist of one line, containing a sequence of at least 1 and at most 40 lowercase letters.

Output Specification:
Output the total number of letters of the longest palindrome contained in the input word.

Sample 1:
In:
Code:
banana

Out:
Code:
5

Sample 2:
In:
Code:
abracadabra

Out:
Code:
3

Spoiler: j4 - Arrival Time
Problem Description:
Fiona commutes to work each day. If there is no rush-hour traffic, her commute time is two hours. However, there is often rush-hour traffic. Specifically, rush-hour traffic occurs from 07:00 (7 AM) until 10:00 (10 AM) in the morning, and 15:00 (3 PM) until 19:00 (7 PM) in the afternoon. During rush-hour traffic, her speed is reduced by half.

She leaves either on the hour (at XX:00), 20 minutes past the hour (at XX:20), or 40 minutes past the hour (at XX:40)

Given Fiona's departure time, at what time does she arrive at work?

Input Specification:
The input will be one line, which contains an expression of the form "HH:MM", where "HH" is one of the 24 starting hours (00, 01, ..., 23) and MM is one of the three possible departure minute times (00, 20, 40).

Output Specification:
Output the time of Fiona's arrival, in the form "HH:MM"

Sample 1:
In:
Code:
05:00

Out:
Code:
07:00

Sample 2:
In:
Code:
07:00

Out:
Code:
10:30

Sample 2:
In:
Code:
23:20

Out:
Code:
01:20

Spoiler: j5 - Tandem Bicycle
Problem Description:
Since time immemorial, the citizens of Dmojistan and Pegland have been at war. Now, they have finally signed a truce. They have decided to participate in a tandem bicycle ride to celebrate the truce. There are N citizens from each country. They must be assigned to pairs so that each pair contains one person from Dmojistan and one person from Pegland.

Each Citizen has a cycling speed. In a pair, the fastest person will always operate the tandem bicycle, while the slower person simply enjoys the ride. In other words, if the members of a pair have speeds "a" and "b", then the bike speed of the pair is max(a,b). The total speed is the sum of the "N" individual bike speeds.

For this problem, in each test case, you will be asked to answer one of two questions:
  • Question 1: what is the minimum total speed, out of all possible assignments into pairs?
  • Question 2: what is the maximum total speed, out of all possible assignments into pairs?

Input Specification:
The first line will contain the type of question you are to solve, which is either 1 or 2.

The second line contains "N" (1 <= N <= 100).

The third line contains N space-separated integers: the speeds of the citizens of Dmojistan.

The fourth line contains N space-separated integers: the speeds of the citizens of Pegland.

Each person's speed will be an integer between 1 and 1000000.

Output Specification:
Output the maximum or minimum total speed that answers the question asked.

Sample 1:
In:
Code:
1 3 5 1 4 6 2 4

Out:
Code:
12

Sample 2:
In:
Code:
2 3 5 1 4 6 2 4

Out:
Code:
15


Bonus challenge: oneline or golf these
It's often the outcasts, the iconoclasts ... those who have the least to lose because they
don't have much in the first place, who feel the new currents and ride them the farthest.

Reply

RE: CCC Junior 2016 [challenges] #2
j1 - Tournament Selection
Code:
score = 0 for i in range(0, 6): a = raw_input() if a == "W": score += 1 groups = { 1: [5, 6], 2: [3, 4], 3: [1, 2], } if score in groups[1]: print(1) elif score in groups[2]: print(2) elif score in groups[3]: print(3) else: print(-1)

NOTE: I know I could've made it a lot shorter, but I just wanted it to be organized.

EDIT: Here is the short, ugly code.
Code:
s = 0 for i in range(0, 6): a = raw_input() if a == "W": s += 1 if s in [5, 6]: print(1) elif s in [3, 4]: print(2) elif s in [1, 2]: print(3) else: print(-1)

Reply

RE: CCC Junior 2016 [challenges] #3
(03-06-2016, 04:01 PM)m0dem Wrote: j1 - Tournament Selection
Code:
score = 0 for i in range(0, 6): a = raw_input() if a == "W": score += 1 groups = { 1: [5, 6], 2: [3, 4], 3: [1, 2], } if score in groups[1]: print(1) elif score in groups[2]: print(2) elif score in groups[3]: print(3) else: print(-1)

NOTE: I know I could've made it a lot shorter, but I just wanted it to be organized.

EDIT: Here is the short, ugly code.
Code:
s = 0 for i in range(0, 6): a = raw_input() if a == "W": s += 1 if s in [5, 6]: print(1) elif s in [3, 4]: print(2) elif s in [1, 2]: print(3) else: print(-1)

you can make your short answer shorter by removing extra space. It's also possible to oneline this using tuples and indexing
Code:
print(-1,3,3,2,2,1,1)[[raw_input() for i in xrange(6)].count('W')]
It's often the outcasts, the iconoclasts ... those who have the least to lose because they
don't have much in the first place, who feel the new currents and ride them the farthest.

[+] 1 user Likes Inori's post
Reply

RE: CCC Junior 2016 [challenges] #4
(03-06-2016, 06:07 PM)Inori Wrote: you can make your short answer shorter by removing extra space. It's also possible to oneline this using tuples and indexing
Code:
print(-1,3,3,2,2,1,1)[[raw_input() for i in xrange(6)].count('W')]

Wow. That's neat code.
As you can probably tell, I'm not too good at code golf. xD

Reply







Users browsing this thread: