Problem A: Happy Camper

Problem A: Happy Camper
Problem A: Happy Camper
As Happy Camper Harry pulls into his favorite campground with his family, he notices the
sign: 'Campground occupancy is limited to 10 days within any consecutive 20-day period.'
Harry is just starting a 28-day vacation. What is the maximum number of days he can
occupy a campsite during his vacation?
We state the problem in more general terms. Suppose that 1 < L < P < V are integers.
Campground occupancy is limited to L days within any consecutive P-day period. Happy
Camper Harry is just starting a V-day vacation. What is the maximum number of days he
can occupy a campsite during his vacation?
Input
The input will contain data for a number of test cases. For each test case, there will be one
line of data, containing values of L, P and V, in that order. All input integers can be
represented by signed 32-bit integers. End of data will be signaled by a line containing three
zeros, which will not be processed.
Output
There will be one line of output for each test case. It will display the case number and the
number of days Happy Camper Harry can occupy a campsite during his vacation. The
format is illustrated by the sample output.
Sample Input
5 8 20
5 8 17
0 0 0
Sample Output
Case 1: 14
Case 2: 11
Problem B
Food Review
Problem ID: foodreview
Frida is a writer for Cosmopolitan who writes restaurant reviews. She enjoys it a lot, but it seems that, throughout the years,
she has reviewed all the restaurants on Earth. It’s now time to
move one level up; she is going to review the food served by the
airlines, so that the readers can make better decisions on which
flights to take.
Her boss gave her a list of flight connections that she needs
to review for the upcoming issue of Cosmopolitan. She knows
that they serve the same food in both directions of every flight, so
she only needs to take it once. She realized that she will need to
take some additional flights, because she can not make all reviews
using only flights in the list from her boss. Therefore she did
Photo by Nelson Pavlosky
some quick research and made a list of additional flights which
she might take. She will not review the food on these flights; they will only be used so that she can make all the
reviews.
Frida’s goal is to make all the reviews while spending the least money on flight tickets. Her office is in
Stockholm, so she starts and ends her journey there. Each flight is both ways between two cities and has a fixed
price in both directions. You can assume that it is possible to finish all the reviews using some of the additional
flights.
For the purposes of this problem we ignore the price Frida has to pay for accommodation and we also ignore
the departure and arrival times of flights by assuming that every flight is very often and reasonably short. We only
focus on the total price of the flights.
Input
The first line contains 2 space separated integers N, R, (2 ≤ N ≤ 13, 0 ≤ R ≤ 78), where N is the number of
airports mentioned in the input and R is the number of flights to review. The airports are numbered 1, . . . , N and
Stockholm has number 1.
The next R lines describe the R flights to review. Each line contains 3 space separated integers a, b, c, (1 ≤
a, b ≤ N, 1 ≤ c ≤ 10 000), where a, b denote 2 distinct airports and c is the cost of the flight in Swedish kronor
in both directions. No pair of 2 cities is listed twice.
The next line contains an integer F , (0 ≤ F ≤ 200), the number of additional flights available. The next F
lines contain descriptions of flights in the same format as above and there may be more flights between a pair of
cities. You may assume that it is possible to make all the reviews using some of these additional flights.
Output
Output one line with one integer – the lowest total cost of flight tickets, such that Frida can make all the reviews
and return back to Stockholm.
Sample Input 1
Sample Output 1
5
1
2
4
2
1
3
3100
3
2 1000
3 1000
5 500
4 300
5 300
NCPC 2012 Problem B: Food Review
Sample Input 2
Sample Output 2
6
1
2
1
2
5
2
2
4
5100
5
2
3
3
4
6
1000
1000
1000
1000
500
5 300
6 300
NCPC 2012 Problem B: Food Review
Problem C
Juice
Problem ID: juice
In the Favela of Rio de Janeiro there was a flicker of light.
After months of careful building, they finally connected the generator to the thousands of extension cords and the slum was illuminated by millions of bright lights. . .
However, the capacity of the extension cords was not enough
to meet the energy demands of all the houses in the slum. Thus,
the engineers had to carefully select which houses should be powered, and which should not, prior to connecting the power generator. Their idea was to power as many houses as possible, based
on the energy demands of each house, and the capacity of the extension cords.
More specifically, the generator and each of the houses are
Photo by Joe Friedrichsen
represented by nodes, and extension cords are represented by
edges between these. Thus, each node gets power from exactly
one other node. In addition, each node except the generator node has a non-negative power demand. The generator produces an amount of energy that far surpasses the total capacity of the extension cords connected to it, and
can thus be treated as an infinite energy source.
Given the same data, find out how many houses the engineers were able to cover the energy demands of.
Input
The first line of the input contains a single integer 0 ≤ n ≤ 1000, the number of houses in the slum.
Then follow n lines in the format pi ri ci , where 0 ≤ pi ≤ n is the parent node of house i, 0 ≤ ri ≤ 100 is the
energy demand of house i and 1 ≤ ci ≤ 100 is the capacity of the extension cord connecting house i to house pi .
The power generator has index 0.
Output
Output the maximum number of power requirements that can be met.
Sample Input 1
Sample Output 1
3
0 3 2
0 100 100
1 1 1
2
NCPC 2012 Problem C: Juice
Problem D: Pills
Aunt Lizzie takes half a pill of a certain medicine every day. She starts with a bottle that
contains N pills.
On the first day, she removes a random pill, breaks it in two halves, takes one half and puts
the other half back into the bottle.
On subsequent days, she removes a random piece (which can be either a whole pill or half a
pill) from the bottle. If it is half a pill, she takes it. If it is a whole pill, she takes one half and
puts the other half back into the bottle.
In how many ways can she empty the bottle? We represent the sequence of pills removed
from the bottle in the course of 2N days as a string, where the i-th character is W if a whole
pill was chosen on the i-th day, and H if a half pill was chosen (0 ≤ i < 2N). How many
different valid strings are there that empty the bottle?
Input
The input will contain data for at most 1000 problem instances. For each problem instance
there will be one line of input: a positive integer N <= 30, the number of pills initially in the
bottle. End of input will be indicated by 0.
Output
For each problem instance, the output will be a single number, displayed at the beginning of
a new line. It will be the number of different ways the bottle can be emptied.
Sample Input
6
1
4
2
3
30
0
Sample Output
132
1
14
2
5
3814986502092304
Problem E: User Names
A university's computer system assigns user names according to the following set of rules:
1. The maximum length of a username is MAXLEN characters. (The value of
MAXLEN will be specified in the input for each problem instance.)
2. The first character of the user name is the first letter of the person's first name,
converted to lower case. Ignore apostrophes and hyphens here and in Step 3.
3. Append as many letters of the person's last name as possible (converted to lower case,
if necessary), without exceeding a total of MAXLEN characters. Starting with the
first letter of the last name, append these letters in the order in whch they appear in
the last name.
4. If a user name assigned on basis of Rules 1 - 3 already exists in the database, break
the tie as follows: append serial numbers 1 - 9, in that order, to the username from
step 3, if that can be done without exceeding the limit of MAXLEN characters in the
username. Otherwise, drop the last letter before appending the serial number.
5. If a user name assigned on basis of Rules 1 - 4 already exists in the database, break
the tie as follows: append serial numbers 10 - 99, in that order, to the username from
step 3, if that can be done without exceeding the limit of MAXLEN characters in the
username. Otherwise, drop the last letter or the last two letters (whichever is
necessary) before appending the serial number.
6. It is assumed that the above rules will avoid ties.
Input
The input will contain data for a number of test cases. The first line of each test case will
contain two positive integers: the number of names and the value of MAXLEN (5 ≤
MAXLEN ≤ 80). This will be followed by the list of names. Each name will consist of at
most 80 characters and will begin with the first name, followed by middle names, if any, and
will conclude with the last name. A single blank space will separate first, middle, and last
names. Any name can contain upper and lower case letters, hyphens, and apostrophes. A
last name will contain at least two letters, other names will contain at least one letter (they
could be just initials). There will be no more than 200 names in each case. The last test case
will be followed by a line containing two zeros for the number of names and MAXLEN.
Output
For each case, the output will begin with a line containing the case number. This will be
followed by the list of user names, one per line, in the same order as the corresponding
names in the input.
Sample Input
2 6
Jenny Ax
Christos H
11 8
Jean-Marie
Jean-Marie
Jean-Marie
Jean-Marie
Jean-Marie
Jean-Marie
Jean-Marie
Jean-Marie
Jean-Marie
Jean-Marie
Jean-Marie
11 9
Jean-Marie
Jean-Marie
Jean-Marie
Jean-Marie
Jean-Marie
Jean-Marie
Jean-Marie
Jean-Marie
Jean-Marie
Jean-Marie
Jean-Marie
0 0
Papadimitriou
d'Arboux
A d'Arboux
B d'Arboux
C d'Arboux
D d'Arboux
D d'Arboux
F d'Arboux
G d'Arboux
H d'Arboux
I d'Arboux
J d'Arboux
d'Arboux
A d'Arboux
B d'Arboux
C d'Arboux
D d'Arboux
D d'Arboux
F d'Arboux
G d'Arboux
H d'Arboux
I d'Arboux
J d'Arboux
Sample Output
Case 1
jax
cpapad
Case 2
jdarboux
jdarbou1
jdarbou2
jdarbou3
jdarbou4
jdarbou5
jdarbou6
jdarbou7
jdarbou8
jdarbou9
jdarbo10
Case 3
jdarboux
jdarboux1
jdarboux2
jdarboux3
jdarboux4
jdarboux5
jdarboux6
jdarboux7
jdarboux8
jdarboux9
jdarbou10
Problem F: Slalom
In spite of the scarcity of snowfall in Syria, interest in winter sports is growing in the country,
especially with regard to skiing. Many people spend several weekends or even full weeks
improving their skills in the mountains.
In this problem we deal with only one of the multiple alpine skiing disciplines: slalom. A
course is constructed by laying out a series of gates, which are formed by two poles. The
skier must pass between the two poles forming each gate. The winner is the skier who takes
the least time to complete the course while not missing any of the gates.
You have recently started to learn to ski, but you have already set yourself the goal of taking
part in the Winter Olympic Games of 2022, for which Syria will presumably present a
candidature. As part of the theoretical training, you need to write a program that calculates,
given a starting point and a series of gates, the minimum-length path starting from the point
given and passing through each gate until you reach the last one, which is the finish line. You
may assume that the gates are horizontal and are ordered from highest to lowest, so that you
need to pass through them in order. You consider yourself an accomplished skier, so you can
make any series of turns, no matter how difficult, and your only concern is minimizing the
total length of the path.
Input
The first line of each case gives the number of gates n (1 ≤ n ≤ 1000). The next line contains
two floating point numbers, the Cartesian coordinates x and y of the starting position, in that
order. Next come n lines with three floating point numbers each, y x1 x2, meaning that the
next gate is a horizontal line from (x1,y) to (x2,y). You can safely assume that x1 < x2. The
values of y are strictly decreasing and are always smaller than that of the starting position.
The last gate represents the finish line. All coordinates are between −500000 and 500000,
inclusive. A value of 0 for n means the end of the input. A blank line follows each case.
Output
For each test case, output a line with the minimum distance needed to reach the finish line.
Your answer should be printed on 11 decimal fraction.
Sample Input
2
0 2
1 1 2
0 0.5 3
3
0
3
2
1
4
1 2
-1 0
1 2
0
Output for Sample Input
2.41421356237
4.24264068712
Problem G: GO
In the game of Go, two players alternate placing black and white stones on lattice points of an
n × n grid, each attempting to surround as much territory (i.e., regions of unfilled lattice
points) as possible. At the end of the game, the score for each player is the total area of the
territory surrounded by his or her stones. Given the locations of black and white stones on a
Go board at the end of a match, your task is to compute the score of each player in order to
determine the winner.1
Formally, two grid lattice points with coordinates (r, c) and (r′, c′) are adjacent if
|r − r′| + |c − c′| = 1. A connected region of unfilled lattice points belongs to one player’s
territory if all adjacent filled lattice points contain stones belonging to that player (see Figure
1). Finally, a player’s score consists of the number of unfilled lattice points in his or her
territory.
1
Note that the scoring of Go boards described here does not correspond exactly to the real game of Go: we make the
simplifying assumptions that all “disputes” have been settled so that any territories surrounded by stones of both colors are
considered neutral, and that all groups on the board are considered “alive.”
Figure 1: Diagram of a 9 × 9 Go board. Unfilled lattice points belonging to black’s territory
are marked with B, and unfilled lattice points belonging to white’s territory are marked
with W. Neutral unfilled lattice points are unmarked. In the game above, white wins by
21 -3 = 18.
Input
The input test file will contain multiple cases, each consisting of three lines. Each test case
begins with a line containing three integers, n (where 1 ≤ n ≤ 19), b, and w (where b ≥ 0,w
≥ 0 and 1≤ b + w ≤ n2). Here, n denotes the size of the board, b is the number of black
pieces placed, and w is the number of white pieces placed. The second line of each test case
contains b pairs of integers r1 c1 . . . rb cb (where 1 ≤ ri , ci ≤ n) indicating the positions of
the b black stones. The third line of each test case contains w pairs of integers r`1 c`1 . . . r`w
c`w (where 1 ≤ r`i , c`i ≤ n) indicating the positions of the w white stones. No two stones will
be located at the same lattice point. Input is terminated by a single line containing only the
number 0; do
not process this line.
Output
For each test case, print either “White wins by ”, “Black wins by ”, or “Draw”. For example:
Sample Input
1 1 0
1 1
2 0 1
1
5
1
1
0
1
12 4
1 1 2 1 3 2 1 2 3 3 1 3 3 4 1 4 3 5 1 5 2 5 3
4 2 4 3 4 3 5
Output for Sample Input
Draw
White wins by 3
Black wins by 1
Problem H: Trees
Problem H: Trees
A graph consists of a set of vertices and edges between pairs of vertices. Two vertices are
connected if there is a path (subset of edges) leading from one vertex to another, and a
connected component is a maximal subset of vertices that are all connected to each other. A
graph consists of one or more connected components.
A tree is a connected component without cycles, but it can also be characterized in other
ways. For example, a tree consisting of n vertices has exactly n-1 edges. Also, there is a
unique path connecting any pair of vertices in a tree.
Given a graph, report the number of connected components that are also trees.
Input
The input consists of a number of cases. Each case starts with two non-negative integers n
and m, satisfying n ≤ 500 and m ≤ n(n-1)/2. This is followed by m lines, each
containing two integers specifying the two distinct vertices connected by an edge. No edge
will be specified twice (or given again in a different order). The vertices are labelled 1 to n.
The end of input is indicated by a line containing n = m = 0.
Output
For each case, print one of the following lines depending on how many different connected
components are trees (T > 1 below):
Case x: A forest of T trees.
Case x: There is one tree.
Case x: No trees.
x is the case number (starting from 1).
Problem H: Trees
Sample Input
6
1
2
3
6
1
2
3
4
5
6
1
2
1
4
5
6
0
3
2
3
4
5
2
3
4
5
6
6
2
3
3
5
6
4
0
Sample Output
Case 1: A forest of 3 trees.
Case 2: There is one tree.
Case 3: No trees.
Problem I: Dolls
Do you remember the box of Matryoshka dolls last week? Adam just got another box of dolls
from Matryona. This time, the dolls have different shapes and sizes: some are skinny, some
are fat, and some look as though they were attened. Specifically, doll i can be represented by
three numbers wi, li, and hi, denoting its width, length, and height. Doll i can fit inside another
doll j if and only if wi < wj , li < lj , and hi < hj .
That is, the dolls cannot be rotated when fitting one inside another. Of course, each doll may
contain at most one doll right inside it. Your goal is to fit dolls inside each other so that you
minimize the number of
outermost dolls.
Input
The input consists of multiple test cases. Each test case begins with a line with a single
integer N, 1 ≤ N ≤ 500, denoting the number of Matryoshka dolls. Then follow N lines, each
with three space-separated integers wi, li, and hi (1 ≤ wi; li; hi ≤ 10,000) denoting the size of
the ith doll. Input is followed by a single line with N = 0, which should not be processed.
Output
For each test case, print out a single line with an integer denoting the minimum number of
outermost dolls that can be obtained by optimally nesting the given dolls.
(Sample input and output on the next page)
Sample Input
3
5 4 8
27 10 10
100 32 523
3
1 2 1
2 1 1
1 1 2
4
1 1 1
2 3 2
3 2 2
4 4 4
0
Output for Sample Input
1
3
2
Problem J: Emergency Room
Problem J: Emergency Room
An emergency room is serviced by a number of doctors. When patients arrive in the
emergency room, their arrival time is recorded and they are assigned a number of
treatments. Each treatment has a priority level and duration. For any particular patient, the
priority levels of successive treatments form a strictly decreasing sequence, such as the
numbers 8, 5, 3 in the following example:
Treatment 1: priority = 8, duration = 10 units of time
Treatment 2: priority = 5, duration = 25 units of time
Treatment 3: priority = 3, duration = 15 units of time
Each treatment must be performed by a doctor; different treatments for the same person do
not need to be performed by the same doctor. Any particular doctor can treat only one
patient at any time.
All doctors of the facility will open their cubicles in the morning and become available at
the same time. Some patients may have already arrived at that time, and additional patients
may arrive subsequently. Whenever there is an available doctor, the patient with the highest
priority (i.e., priority of the next treatment to be performed) will be selected from the
waiting room and assigned to the available doctor. In case of a tie, the person with earliest
original arrival time will be chosen. When more than one doctor is available, more than one
patient may be admitted to the next treatment at the same time.
When, for a particular patient, a treament has been completed, but there are still remaining
treatments pending, the patient will return to the waiting room and wait for his/her next turn.
When all of a particular patient's scheduled treatments have been completed, the patient will
be released from the facility.
Problem J: Emergency Room
Input
The input will contain data for several test cases. Under each test case, the first line of input
will contain two positive integers: the number of doctors at the facility, and the clock
reading at which the doctors become available in the morning. All times in the input will be
expressed in some unspecified unit of time, as a single positive integer up to 1000. The
remainder of the input for each test case will provide information about the patients. Under
each patient, the first line will state the arrival time. The remaining lines under each patient
will specify the pending treatments for that patient, one line per treatment. Each treatment
will be represented by two positive integers: priority and duration. Under each patient, the
priorities will be in strictly decreasing order. No two patients have the same arrival time.
The patients will be listed in increasing order of arrival times. A line containing two 0s will
mark the end of each patient's data, a line containing -1 will mark the end of each test case,
and another line containing two 0s will mark the end of input. There will be at most 500
doctors and 500 patients in each case. The maximum priority and duration for any treatment
is 100.
Output
After printing the case number, the output will display the time when each patient can be
released from the emergency room. Patients will be identified by their arrival times; they
will be listed in increasing order of release times. If there are several patients released at the
same time, display them in the order of original arrival times. See the sample output for the
exact format.
Problem J: Emergency Room
Sample Input
1 50
10
10 5
5 20
4 5
0 0
30
25 10
8 5
5 5
0 0
110
20 10
0 0
-1
2 50
10
10 5
5 20
4 5
0 0
30
25 10
8 5
5 5
0 0
110
20 10
0 0
-1
0 0
Sample Output
Case 1:
Patient
Patient
Patient
Case 2:
Patient
Patient
Patient
30 released at clock = 95
10 released at clock = 100
110 released at clock = 120
30 released at clock = 70
10 released at clock = 80
110 released at clock = 120
Problem K : Indomie
During recession, Amjad needs to queue for SembakoPlus. Sembako, as we all know, stands
for “Sembilan Bahan Pokok” which consists of 9 kinds of item: Rice, Sugar, Cooking-oil,
Meat, Egg, Milk, Corn, Kerosene and Iodized Salt. SembakoPlus consists of Sembako and
one more item: Indomie! Amjad’s favorite of all time!! (therefore, no wonder why he could
stand for this long queue).
Each person in the queue is allowed to pick only one item. No need to ask, Amjad wants only
Indomie. Unfortunately, they are running out of SembakoPlus stock and currently there are
three kinds of item left: Rice, Sugar and Indomie. As he could see from afar, he is quite sure
that Rice and Sugar will be enough for everybody.
Given the number of remaining Indomie and the number of people queuing in front of
Amjad, your task is to count the probability that he will get his Indomie. Amjad can’t do
programming right now as he is very nervous so he can’t think logically. He needs your help!
Input
There will be multiple test cases for this problem. Each test case contains two integers N
(1 ≤ N ≤ 50) and S (0 ≤ S ≤ 50), where N is the number of people queuing in front of Amjad
and S is the remaining number of Indomie.
Output
For each case, print in a single line the probability in percentage that he will get his Indomie
with 5 digits precision (he’s being paranoid)
(Sample input and output on the next page)
Sample Input
2 1
3 2
4 0
4 1
10 10
14 9
30 14
Output for Sample Input
50.00000
76.92308
0.00000
33.33333
99.99831
98.65515
95.16071
Explanation for 1st sample test case:
There are two peoples queuing in front of Amjad, so those two peoples could pick of the
following combination {1st people, 2nd people}:
1. Rice, Rice
2. Rice, Sugar
3. Rice, Indomie
4. Sugar, Rice
5. Sugar, Sugar
6. Sugar, Indomie
7. Indomie, Rice
8. Indomie, Sugar
Since there is only one Indomie left, there are only 4 out of 8 combinations that ensure Amjad
to get his Indomie (1, 2, 4 and 5), hence the probability is 4/8 = 50%.
Problem L
Galactic Warlords
Problem ID: galactic
Correct version
Will the galaxy see peace at last? All the warlords have gathered
to divide all of space between themselves. The negotiations have
come quite far and the warlords have finally agreed on a peaceful
way of deciding who gets what. The 2-dimensional galactic map
must first be divided into sectors by splitting it along a set of infinite lines. The warlord with the largest battle fleet will choose one
sector, then the warlord with the second largest fleet will choose
some other sector and so on, until everyone has gotten a sector.
This is then repeated until there are no sectors left.
Different sets of lines have been suggested, and it is up to
you to present these alternatives to the meeting. To make sure
that there will be peace, you are ready to modify the suggestions
slightly. You have some experience with warlords and know that
no warlord will settle for less space than anyone else, so for there
Phto by NASA, ESA, G. Illingworth, D. Magee, and P. Oesch (University of California,
Santa Cruz), R. Bouwens (Leiden University), and the HUDF09 Team.
to be peace, all of them must get the exact same area on the map.
Since space is infinite, so is the map. Some sectors will therefore have infinite area, so that is the amount of space
everyone will want. How many extra lines will you have to add to make sure each warlord can get at least one
sector with infinite area?
Input
The first line of input contains two positive integers W and N , (1 ≤ W, N ≤ 100) denoting the number of
warlords and the number of lines in the suggested division of space. This is followed by N lines each containing
four integers x1 , y1 , x2 and y2 , each with an absolute value no higher than 10 000. This means that one line is
intersecting the two points (x1 , y1 ) and (x2 , y2 ) on the galactic map. These two points will not be the same.
Output
Output the number of lines you will have to add to this suggestion to satisfy all warlords.
Sample Input 1
Sample Output 1
2 1
1 1 -2 0
0
Sample Input 2
Sample Output 2
5
0
0
2
1
3
5 5 5
0 1 1
2 3 3
NCPC 2012 Problem L: Galactic Warlords
Problem M
Horror List
Problem ID: horror
It was time for the 7th Nordic Cinema Popcorn Convention, and
this year the manager Ian had a brilliant idea. In addition to the
traditional film program, there would be a surprise room where a
small group of people could stream a random movie from a large
collection, while enjoying popcorn and martinis.
However, it turned out that some people were extremely disappointed, because they got to see movies like Ghosts of Mars,
which instead caused them to tear out their hair in despair and
horror.
To avoid this problem for the next convention, Ian has come up
with a solution, but he needs your help to implement it. When the
group enters the surprise room, they will type in a list of movies
in a computer. This is the so-called horror list, which consists of
bad movies that no one in the group would ever like to see. Of
course, this list varies from group to group.
You also have access to the database Awesome Comparison
of Movies which tells you which movies are directly similar to
which. You can assume that movies that are similar to bad movies
will be almost as bad. More specificly, we define the Horror index
as follows:

 0
Q+1
HI =

+∞
if movie is on horror list. This overrides the other definitions.
if the worst directly similar movie has HI = Q
if not similar at all to a horrible movie
Photo by Janet Hudson
Input
The first line of input contains three positive integers N , H, L (1 ≤ H < N ≤ 1000, 0 ≤ L ≤ 10000), where N
is the number of movies (represented by IDs, ranging from 0 to N − 1), H is the number of movies on the horror
list and L is the number of similarities in the database.
The second line contains H unique space-separated integers xi (0 ≤ xi < N ) denoting the ID of the movies
on the horror list.
The following L lines contains two space-separated integers ai , bi (0 ≤ ai < bi < N ), denoting that movie
with ID ai is similar to movie with ID bi (and vice verca).
Output
Output the ID of the best movie in the collection (highest Horror Index). In case of a tie, output the movie with
the lowest ID.
Sample Input 1
Sample Output 1
6
0
0
1
4
3
0
1
3 5
5 2
1
2
5
5
2
NCPC 2012 Problem M: Horror List
Sample Input 2
Sample Output 2
6
5
0
0
3
3
2 3
2
5
1
4
NCPC 2012 Problem M Horror List
Problem N
Infiltration
Problem ID: infiltration
Rookie Pirate Captain Jack Albatross has secretly laid anchor
in a hidden bay not far from Port Wine, the local meeting point for
grizzled pirates and denizens of the sea. Disguising as a messenger, you have infiltrated the service of the dreaded legendary Captain Stevie, and you are entrusted with carrying small encrypted
messages between Captain Stevie and his staff of shipmates. Your
task is to break the encryption of the messages in aid of young
Captain Albatross, giving him a much needed edge in his quest
for peg-legged fame. Fortunately, you (in contrast to Captain Albatross) have been around for a while and you’ve come to know
what words to expect in written pirate messages. The following is
a table of words having common occurrences:
“be”
“dead”
“sable”
“our”
“hook”
“avenge”
“rum”
“ship”
“parrot”
“will”
“blood”
“captain”
Illustration by: Mike Holmesfour, used under CC Attribution Noncommercial 3.0
Unported License
In a (mixed alphabet) substitution cipher, each letter of the
plain text is replaced with another, in this case arbitrary but
unique, letter from the alphabet. Given a text encrypted with a
substitution cipher and the given set of the twelve known words
above, your task is to decode the encrypted text and provide us and Captain Albatross with the plain text. This
can be accomplished if and only if there is a unique substitution mapping from the encrypted letters to plain text
letters such that
1. a subset S of the twelve words show up in the plain text, and
2. the number of different letters in the words in S is equal to the number of different letters in the encrypted
text.
Note that not all the known words may be present in the plain text and that replacements are not mutual (’a’ being
encrypted by ’h’ does NOT necessarily mean that ’h’ is encrypted by ’a’).
Input
A text encrypted by a substitution cipher.
The encrypted text is given on one line containing at most 200 characters from the set [’a’-’z’,’ ’]. Only the
letters [’a’-’z’] of the plain text are encrypted, the spaces are kept unencrypted.
Output
The decrypted plain text if possible, or the string “Impossible” if the text cannot be uniquely decrypted using
the set of known words.
Sample Input 1
Sample Output 1
ex eoii jpxbmx cvz uxju sjzzcn jzz
we will avenge our dead parrot arr
Sample Input 2
Sample Output 2
wl jkd
Impossible
Sample Input 3
Sample Output 3
dyd jkl cs
Impossible
NCPC 2012 Problem N: Infiltration