2009 Koi PDF
2009 Koi PDF
2009 Koi PDF
2008
Trimmed Mean
In sports such as gymnastics or diving, sometimes a judge tends to give biased scores depending on
his likes or dislikes on an athlete. By including these biased scores to an averaged score, it is unfair to
the player. To prevent this situation, trimmed mean or Winsorized mean is used.
For example, seven judges gave the following score:
9.3, 9.5, 9.6, 9.8, 9.1, 5.0, 9.3
The total sum is 61.6, which gives the average to be 8.8. This average is a result of one low score of
5.0 that may seem unfair to the contestant.
The above scores are sorted in ascending order:
5.0, 9.1, 9.3, 9.3, 9.5, 9.6, 9.8
Trimmed_Mean(7,2) represents discarding two lowest and two highest scores and calculating the
average only without those, 9.3, 9.3, and 9.5, which gives the average of 9.37 rounding up to two
decimal places.
Winsorized_Mean(7,2) represents, in ascending order, replacing two lowest and two highest score
with the next closest score: 9.3, 9.3, 9.3, 9.3, 9.5, 9.5, 9.5. Now the average becomes 9.39 rounding up
to two decimal places.
Write a program that calculates Trimmed_Mean(N,K) and Winsorized_Mean(N,K) where N
represents the total number of scores and K represents number of scores getting discarded or replaced
from each side in ascending order.
The maximum running time is 0.5 seconds.
Input Format (Input.txt)
The first line has the values of N (3N100,000) and K (0K(N/2)-1) with a space in between. Then
there are N lines with each score on each line. The scores are real numbers (0score10) rounds up to
one decimal place.
Output Format (Output.txt)
The first line should print out the result from Trimmed_Mean(N,K) and second line from
Winsorized_Mean(N,K) with the answers round up to two decimal places. For example, if the
answer is 9.667, round up to 9.67, 5 to 5.00, and 5.5 to 5.50.
World Cup
In World Cup final qualification tournament, six countries make a group to match against the
countries in a same group so that each country has total of five games. After the tournament, a
reporter sent the results of the games. We are to determine if the number of wins, draws, and loses of
the countries are possible.
The followings are examples of possible and impossible results.
<Example 1> Possible Result
Country
Win
Country
Win
Draw Lose
Draw Lose
Country
Win
Country
Win
Draw Lose
Draw Lose
Write a program that prints out 1 when the result is possible and 0 if not when there are total of 4
different results.
The maximum running time is 0.5 seconds. There are no partial credits.
Input Format (Input.txt)
Having four lines, each line has 18 numbers that are the results - wins, draws, and loses - of six
countries in a same group with a space in between each numbers.
Output Format (Output.txt)
The output prints out 1 if the results are possible and 0 if not for 4 different results in one line with a
space in between.
Stepping on Tiles
On the way to KOI venue, there are tiles lined up. Each tile has a natural number on it. Jason realized
that the numbers on tiles are different and it was lined up in an increasing order. He tries to get to the
venue by starting at a certain tile and stepping on tiles in order that increases with certain natural
number.
Jason, however, realized that the number of tiles to step on consecutively depends on which tile to
start and how much to increment each time to step on the different tile.
Jason decided to calculate the maximum sum of the natural numbers that were on the tiles that he
stepped on the way to the venue as it was described the above. The tiles to step on consecutively need
to be more than three.
For example, there are tiles with natural numbers lined up in the following way:
1, 2, 6, 7, 11, 12, 13, 15, 17, 20, 23
All the possible ways to step on more than three tiles, consecutively, are represented in the table below.
Increasing Amount
Order of Tiles
Sum
11, 12, 13
36
56
17, 20, 23
60
7, 11, 15
33
2, 7, 12, 17
38
1, 7, 13
21
11, 17, 23
51
6, 13, 20
39
7, 15, 23
45
2, 11, 20
33
11
1, 12, 23
36
Therefore, in this example, the possible maximum sum of natural numbers on tiles that Jason stepped
on consecutively more than three times is 60 including the natural number on the staring tile.
Write a program that determines the maximum sum of the numbers on the tiles that Jason can step on
consecutively more than three times, as the tiles are lines up in increasing order. If there are no more
than three tiles that can be stepped on consecutively, print out 0.
The maximum running time is 0.3 seconds. There are no partial credits.
2 3 4 5 6 7 8 9
2 7 2 6 8 2 5 2
Number
Points
Table 2 shows whether a student got it right (O) or wrong (X) for each question.
<Table 2>
Question
Number
Points
O X O O O X X O X
Then, the possible points for each question are shown below in Table 3. The total sum is now 39.
<Table 3>
Question
2 3 4
6 7 8 9
0 7 9 15 0 0 5 0
Number
Points
There are numbers, however, that cant be possible as a total sum such as 73, in this case with the
points given in Table 1.
There will be a natural number K given with point for each question. Write a program that finds the
smallest total sum M (KM) that is not possible.
The maximum running time is 1 second. There will be no partial credits.
Input Format (Input.txt)
The first line has a natural number N which represents the number of questions (1N150). The next
line has point (1point100) for each question in order with a space in between. The natural
Snails
There are N number of snails inside a square that is fenced around. All snails start at the same time
from their own starting points and move by the following rules listed below.
1. All snails have different starting points.
2. All snails have their own direction and only move straight from the direction they are given.
3. All snails have the velocity of 1cm per second.
4. Snails stop when they hit the fence.
5. When a snail reaches the path that is crossed by another snail, it stops.
6. If two or more snails reach at a point at the same time, they all stop.
The following picture shows the movement of nine snails. In the picture below, the side of a cell is
1cm.
In the picture above, snail C stopped as it reached the pathway of snail B, which stopped as it reached
snail As pathway. Snail E stopped as it reached the fence. Determine how long it takes for N number
of snails to stop as each of them is given the starting point and direction by rounding up the time to
two decimal places. As in the picture above, the last snail to stop is snail A and the total time for all
snails to stop is 10.67 seconds.
The maximum running time is one second. There are no partial credits.
Input Format (Input.txt)
The first line has N which represents the total number of snails (1N1,000) and L which represents
the length of one side of the fence in centimeter (10L10,000). The coordinate of lower left corner is
(0, 0) and of upper right corner is (L, L) of the fence. For next N lines, each line has four natural
numbers - x, y, p, q (0 x, y, p, q L) - that represent each snails starting point and direction where
(x, y) represents the starting point and (p-x, q-y) represents the direction vector. Note that point (x, y)
and point (p, q) cant be the same.
Output Format (Output.txt)
Print out the time that it took for all the snails to stop in the first line by rounding up to two decimal
places. Be sure to print only up to two decimal places, for example, if the time is 10.667, 5, or 5.5,
print out 10.67, 5.00, and 5.50, respectively.
Phylogenetic Tree
In bioinformatics, it is very important to form a relationship among various biological species or other
entities that are believed to have a common ancestor. Usually, this relation is represented as a
phylogenetic tree. Each taxonomic unit is represented as a leaf node in the tree. In phylogenetic tree,
the distance of a branch between two leaf nodes show how much they are related in evolutionary
biology. The picture below shows the example of a phylogenetic tree.
Referring to the phylogenetic tree, we can define the graph that shows the closeness among the
taxonomic units as in an explanation of evolutionary biology. This graph is called phylogenetic graph.
Similarity K is defined as follows. The vertices of a graph represent each taxonomic unit. The edge of
a graph exists if and only if the distance (the path length) of the nodes that are corresponding to the
vertices in the phylogenetic tree needs to be less than or equal to K. The picture shown below is the
similarity 3 phylogenetic graph as it was defined from the phylogenetic tree above.
In the laboratory, after constructing a phylogenetic graph, the phylogenetic tree was lost. Therefore,
the work needs to be done to reconstruct the phylogenetic tree.
Write a program that determines the phylogenetic tree when similarity 3 phylogenetic tree is given.
Note that the given phylogenetic graph is always connected and the corresponding phylogenetic tree
always exists.
The maximum running time is one second. There are no partial credits.
Input Format (Input.txt)
The first line has a natural number N which represents vertices of a phylogenetic graph (2N5,000).
The vertices are numbered from 1 to N. The second line has a natural number M that is edges of a
phylogenetic graph (1M1,000,000). For M numbers of lines, each line has two numbers, v and w
(1v, w1,000), that are the two vertices of an edge.