Você está na página 1de 20

KTH Challenge 2013 Stockholm, 21th April 2013

Problems
A B C D E F G H I Car Game Peragrams Vacuum Tubes Chicken Joggers Hogwarts Bank Queue Forest Highway FreeCell Flag Quiz

This page is intentionally left (almost) blank.

KTH Challenge 2013 Problem A


Car Game
Problem ID: cargame
Traveling by car can sometimes be very boring. The natural cure for this boredom is to play a word game. In the following example the winner is he or she who has won the most rounds when the car stops. Each round starts with someone reading out loud the three letters on the license plate of an oncoming car. Whoever is rst to say a word containing those letters in the same order wins the round. On the last road trip you failed miserably in this game, but this time you will be more prepared.
PMS 657U 100% PMS 657U 30%

SVART 100%

Task
For each set of three letters nd the rst word in a dictionary that contains these letters in the same order.

Input
The rst line of input contains two positive integers N 5 000 and M 10 000, the number of words in the dictionary and the number of license plates to be handled. Each of the following N lines contains a word from the dictionary, a string no more than 100 characters long containing only lower case letters from the English alphabet. This is followed by M lines each containing a string of three uppercase letters from the English alphabet, representing a license plate.

Output
For each license plate in the input you should output one line containing either the rst valid word in the dictionary or the sentence No valid word if no such word exists. Sample Input 1 5 3 banana car sand uncharacteristically counterrevolutionaries RRR DNA SND Sample Output 1 counterrevolutionaries No valid word sand

KTH Challenge 2013 Problem A: Car Game This work by KTH CSC is licensed under a Creative Commons Attribution-Share Alike 2.5

This page is intentionally left (almost) blank.

KTH Challenge 2013 Problem B


Peragrams
Problem ID: peragrams
Per recently learned about palindromes. Now he wants to tell us about it and also has more awesome scientic news to share with us. A palindrome is a word that is the same no matter whether you read it backward or forward, Per recently said in an interview. He continued: For example, add is not a palindrome, because reading it backwards gives dda and its actually not the same thing, you see. However, if we reorder the letters of the word, we can actually get a palindrome. Hence, we say that add is a Peragram, because it is an Photo by Ross Beresford anagram of a palindrome. Per gives us a more formal denition of Peragrams: Like I said, if a word is an anagram of at least one palindrome, we call it a Peragram. And recall that an anagram of a word w contains exactly the same letters as w, possibly in a different order.
PMS 657U 100% PMS 657U 30%

SVART 100%

Task
Given a string, nd the minimum number of letters you have to remove from it, so that the string becomes a Peragram.

Input
Input consists of a string on a single line. The string will contain at least 1 and at most 1 000 characters. The string will only contain lowercase letters a-z.

Output
Output should consist of a single integer on a single line, the minimum number of characters that have to be removed from the string to make it a Peragram. Sample Input 1 abc Sample Input 2 aab Sample Output 1 2 Sample Output 2 0

KTH Challenge 2013 Problem B: Peragrams This work by KTH CSC is licensed under a Creative Commons Attribution-Share Alike 2.5

This page is intentionally left (almost) blank.

KTH Challenge 2013 Problem C


Vacuum Tubes
Problem ID: vacuum
In the X-ray lab at KTH some experiments require evacuated tubes between source and sample and between sample and detector so that the X-rays are not absorbed by the air. Since the positions of object and detector vary between different experiments, several tubes of different lengths are available. The tubes should be xed together in pairs, since they have a vacuum window only in one end. Two such tube pairs should be chosen, one to place between the source and the object and one to place between the object and the detector. This, however, gives a large set of possible lengths and makes it difcult to gure out which tubes to use for an experiment. The length of the tubes used should be as long as possible to minimize air absorption, but there is a limited amount of space between source and object L1 and between object and detector L2 . What is the maximum length of air that can be replaced by vacuum tubes in this way?
PMS 657U 100% PMS 657U 30%

SVART 100%

Task
Given a set of tube lengths and the two distances L1 and L2 , nd four tubes with the total length being as long as possible under the constraint that the sum of the rst two tube lengths is at most L1 and the sum of the last two tube lengths is at most L2 .

Input
The rst line of input contains three positive integers, L1 and L2 , denoting the distances explained above in mm (1 L1 , L2 10 000) and N , the number of available tubes (4 N 2 000). The following N lines each contain a single positive integer less than or equal to 10 000, the length of a tube in mm.

Output
Output one line containing the maximum total length of air that can be avoided, i.e., the sum of the four tubes chosen. If there are no two pairs of tubes tting into the setup, output the single word Impossible instead. Sample Input 1 1000 2000 7 100 480 500 550 1000 1400 1500 Sample Output 1 2930

KTH Challenge 2013 Problem C: Vacuum Tubes This work by KTH CSC is licensed under a Creative Commons Attribution-Share Alike 2.5

KTH Challenge 2013


Sample Input 2 200 300 6 100 100 200 200 300 300 Sample Output 2 Impossible

SVART 100%

PMS 657U 100%

PMS 657U 30%

KTH Challenge 2013 Problem C: Vacuum Tubes This work by KTH CSC is licensed under a Creative Commons Attribution-Share Alike 2.5

KTH Challenge 2013 Problem D


Chicken Joggers
Problem ID: joggers
In the woods of Lill-Jansskogen, there is a network of trails that are often used by joggers. The trails have been much appreciated, and have been specially selected by the professors of the Royal Institute of Technology, enabling university students to take a short break from their studies and refresh their smart minds. Strangely enough, the network of trails actually form a tree. When the trails were selected, the professors of the university took the set of trails that Photo by David Spencer they found in Lill-Jansskogen and created a minimum spanning tree, in order to encourage and inspire computer science students to participate in physical activities by applying graph theory in the beautiful surroundings of the Royal Institute of Technology. Unfortunately, the computer science students are not that brave. Winter is approaching, and it is getting darker and darker in the city of Stockholm. Recently, a bunch of programmers from CSC (Community of Scared Cowards) have been complaining that it is too dark in parts of the trail network at night. Some of the trails are lit up by lamps, but sometimes that is not enough for the CSC. They would like to see that all the trails that they might use are lit up properly! You have been tasked with satisfying the cowards by placing lamps at intersections. For economic reasons, it might not be possible to place lights at all intersections, so it will sufce to make sure that there is a lamp in at least one of the two intersections adjacent to a trail that could possibly be used by the joggers. Some intersections already have lamps, and of course, you can keep using those lamps. You dont know exactly what trails the joggers are using, but you do know that the joggers will always start and nish at the university campus. You also know that joggers are training for an upcoming marathon, so they always run exactly S meters in total. A jogger might turn around at any point in time, even in the middle of a trail and she can do so as many times as she wants, in order to fulll the requirement of running exactly S meters.
PMS 657U 100% PMS 657U 30%

SVART 100%

Task
You will be given a map of the woods and the jogging trails included in the minimum spanning tree created by the professors. It is guaranteed that there is exactly one route between each pair of intersections, where a route is a set of adjacent trails. Your task is to nd the minimum number of additional lamps you needed in order to satisfy the frightened runners, no matter which trails they use (subject to the restrictions above)

Input
Input starts with two integers N (2 N 50 000), and S (1 S 104 ), the number of intersections and the total distance in meters that a jogger wants to run, respectively. Then follow N 1 lines with three integers a (1 a N ), b (1 b N ), d (1 d 100), meaning that there is a bidirectional trail between intersection a and b with length d meters. KTH Challenge 2013 Problem D: Chicken Joggers This work by KTH CSC is licensed under a Creative Commons Attribution-Share Alike 2.5 7

KTH Challenge 2013


Then follows a line with a single integer L (0 L N ), the number of lamps that have already been placed. Then follow L distinct integers 1 , . . . , L on one line, meaning there is already a lamp placed at intersections 1 , . . . , L . The university campus is at intersection number 1.

Output
Output contains a single integer, the minimum number of additional lamps you need to place in order to satisfy the joggers requirements. Sample Input 1
SVART 100% PMS 657U 100%

Sample Output 1 1

5 1 1 4 3 1 1

6 2 3 3 5

PMS 657U 30%

1 1 3 2

Sample Input 2 5 1 1 4 3 1 3 6 2 3 3 5 1 1 3 2

Sample Output 2 1

Sample Input 3 5 1 1 1 1 2 4 6 3 4 5 2 3 3 2 3 2

Sample Output 3 1

KTH Challenge 2013 Problem D: Chicken Joggers This work by KTH CSC is licensed under a Creative Commons Attribution-Share Alike 2.5

KTH Challenge 2013 Problem E


Hogwarts
Problem ID: hogwarts
The new semester at Hogwarts has just started, but something is not quite right the staircases are not cooperating with the school administrators! Hogwarts has a single room of movable staircases connecting the N oors. There are M staircases in total, and no two staircases connect the same pair of oors (and, obviously, a staircase would not connect a oor to itself these are smart magic staircases with dignity). The only way to manipulate the staircases is by pressing red and green buttons located on each oor. The oors are labeled in some manner by the integers 0 through N 1. Pressing the red button on oor i (0 i N 1) has the following effect on the staircases. Any staircase that is currently not connected to oor i does not move. Suppose a staircase connects oors i and j (j = i). After pressing the red button on oor i, it will instead connect oors i and j + 1 mod N unless j + 1 mod N = i, in which case it will connect oors i and j +2 mod N = i +1 mod N instead. Pressing the green button is simply the inverse operation of pressing the red one on the same oor (or, equivalently, the same as pressing the red one N 2 times). While alone, the staircases got all messed up. The school adminstrators have presented a plan for how they would rather like the staircases to be placed. You, a low-ranking house elf, have been given the task to x this.
PMS 657U 100% PMS 657U 30%

SVART 100%

Task
Find some sequence of at most 250 000 button presses that will change the staircase room from its current state to the desired state.

Input
There is a single test case. On the rst line N and M are given (3 N 50, 0 M N (N 1)/2). Then follow M lines with pairs of integers i, j (0 i, j N 1), describing the current state of the room of staircases. Each such line means that there is a staircase connecting oors i and j . After this follow another M lines with pairs of integers i, j , describing the desired state of the room of staircases.

Output
On the rst line of output, write a single integer Q (0 Q 250 000), the length of your sequence of button presses. Then print Q lines, each being either R i or G i for some i (0 i N 1), meaning that the red or green button on oor i should be pressed.

KTH Challenge 2013 Problem E: Hogwarts This work by KTH CSC is licensed under a Creative Commons Attribution-Share Alike 2.5

KTH Challenge 2013


Sample Input 1 5 0 0 1 2 0 0 2 2
SVART 100%

Sample Output 1 2 R 0 G 2

4 1 3 2 4 2 4 3 4
PMS 657U 30%

PMS 657U 100%

Sample Input 2 3 0 0 1 0 1 0 3 1 2 2 1 2 2

Sample Output 2 0

KTH Challenge 2013 Problem E: Hogwarts 10 This work by KTH CSC is licensed under a Creative Commons Attribution-Share Alike 2.5

KTH Challenge 2013 Problem F


Bank Queue
Problem ID: bank
Oliver is a manager of a bank near KTH and wants to close soon. There are many people standing in the queue wanting to put cash into their accounts after they heard that the bank increased the interest rates by 42% (from 0.01% per year to 0.0142% per year). However, there are too many people and only one counter is open which can serve one person per minute. Greedy as Oliver is, he would like to select some people in the queue, so that the total amount of cash stored by these people is as big as possible and that money then can work for the bank overnight. There is a problem, though. Some people dont have the time to wait until the bank closes because they have to run somewhere else, so they have to be served before a certain time, after which they just leave. Oliver also turned off the infrared door sensor outside the bank, so that no more people can enter, because its already too crowded in the hall.
PMS 657U 100% PMS 657U 30%

SVART 100%

Task
Help Oliver calculate how much cash he can get from the people currently standing in the queue before the bank closes by serving at most one person per minute.

Input
The rst line of input contains two integers N (1 N 10 000) and T (1 T 47), the number of people in the queue and the time in minutes until Oliver closes the bank. Then follow N lines, each with 2 integers ci and ti , denoting the amount of cash in Swedish crowns person i has and the time in minutes from now after which person i leaves if not served. Note that it takes one minute to serve a person and you must begin serving a person at time ti at the latest. You can assume that 1 ci 100 000 and 0 ti < T .

Output
Output one line with the maximum amount of money you can get from the people in the queue before the bank closes. Sample Input 1 4 4 1000 1 2000 2 500 2 1200 0 Sample Output 1 4200

KTH Challenge 2013 Problem F: Bank Queue 11 This work by KTH CSC is licensed under a Creative Commons Attribution-Share Alike 2.5

KTH Challenge 2013


Sample Input 2 3 4 1000 0 2000 1 500 1 Sample Output 2 3000

SVART 100%

PMS 657U 100%

PMS 657U 30%

KTH Challenge 2013 Problem F: Bank Queue 12 This work by KTH CSC is licensed under a Creative Commons Attribution-Share Alike 2.5

KTH Challenge 2013 Problem G


Forest Highway
Problem ID: forest
The Slovak Government is building a highway from Bratislava to Koice. The highway will pass through a forest where a lot of animals live. Frog Gizela, the queen of the animals, wants to calculate the impact of the highway on their lives. Since the highway will be noisy, animals dont want to live within distance d from the highway. Gizela wants to know how large the inhabitable area will be. If the total inhabitable area of the forest is too small, Gizela will have to nd a new forest for her kingdom.
PMS 657U 100% PMS 657U 30%

SVART 100%

Task
You are given a description of the forest and the highway. The forest is a simple polygon, i.e. its sides do not cross, and the highway can be considered a straight line of width zero. You are also given d, the safe distance from the highway. Calculate the size of the inhabitable area of the forest.

Figure G.1: Drawing of the sample input

Input
The rst line of the input contains one integer N (3 N 250 000) denoting the number of vertices of the polygon. N lines follow with two oating point numbers xi and yi , denoting that the i-th point of the polygon is (xi , yi ). Next line contains 4 oating point numbers xa , ya , xb , yb , denoting that the highway passes through points (xa , ya ) and (xb , yb ). The last line of the input contains one positive oating point number d, the safe distance from the highway. All oating point numbers will be at most 100 000 in absolute value and will have at most 4 digits after the decimal point.

KTH Challenge 2013 Problem G: Forest Highway 13 This work by KTH CSC is licensed under a Creative Commons Attribution-Share Alike 2.5

KTH Challenge 2013


Output
Output one line with one number the size of the inhabitable area of the forest. Results with relative or absolute error 107 will be considered correct. Sample Input 1 7 0.0 0.0 2.0 4.0 4.0 0.0 5.0 5.0 1.0 6.0 1.0 4.0 -1.0 3.0 -2.0 4.0 6.0 1.0 0.6
PMS 657U 30%

Sample Output 1 13.082798910

SVART 100%

PMS 657U 100%

KTH Challenge 2013 Problem G: Forest Highway 14 This work by KTH CSC is licensed under a Creative Commons Attribution-Share Alike 2.5

KTH Challenge 2013 Problem H


FreeCell
Problem ID: freecell
FreeCell Solitaire is, just as computer science, mostly about sorting. The goal is to sort a deck of cards using a fairly convoluted algorithm. The rules are the following: A shufed deck is laid out in eight stacks. Only the topmost card of a stack may be moved. A card of value v may be moved to the top of another stack only if the column is empty, or if the topmost card of the destination stack is of the opposite color and of value v + 1. For instance the three of hearts may be moved on top of the four of clubs. At your disposal you have four free cells (think of them as the available memory if you like!) that are initially empty. Free cells can hold at most one card each, which can be moved according to the same rules as stack cards. Figure H.1 below illustrates a few legal moves.
PMS 657U 100% PMS 657U 30%

SVART 100%

Figure H.1: Legal moves for the three of hearts and six of clubs

Most FreeCell computer games allow you to move a pile of cards, provided there are enough empty cells and empty stacks to accomplish this by moving cards from the pile one by one. In the image above for instance, the whole pile with 5, 4 and 3 can be moved over 6 of spades by using some of the free cells and the empty stack to temporarily hold 3 and 4.

Task
You would like to move a sorted pile of K cards from one stack to the top of another stack which is non-empty, but of appropriate color and value. You will ignore all other non-empty stacks, because otherwise you would have to take into account the color and value of the topmost card of those stacks and that would be too complicated. Even though you ignore the other non-empty stacks, you can still use N free cells and M empty stacks. Is it possible to perform this move?

KTH Challenge 2013 Problem H: FreeCell 15 This work by KTH CSC is licensed under a Creative Commons Attribution-Share Alike 2.5

KTH Challenge 2013


Input
The input consists of several test cases. Each test case is represented by a line with three numbers N , M and K respectively. N is the number of free cells, M is the number of empty stacks and K is the size of the pile you are moving. We are considering a generalized form of Free Cell in which 0 N, M 5 and 0 K 100.

Output
The program should print yes if it is possible to move a pile of K cards using N free cells and M empty stacks, and no otherwise.
SVART 100% PMS 657U 100%

Sample Input 1
PMS 657U 30%

Sample Output 1 yes Sample Output 2 no

3 1 8 Sample Input 2 3 1 9

KTH Challenge 2013 Problem H: FreeCell 16 This work by KTH CSC is licensed under a Creative Commons Attribution-Share Alike 2.5

KTH Challenge 2013 Problem I


Flag Quiz
Problem ID: agquiz
In the intergalactic low budget streaming show Flag quiz!, contestants need to answer questions along the lines of What are the joint colors, symbols and shapes occurring on the ags of Empire X ?. An empire in this context is simply some subset of entities on the same planet, or otherwise related, according to the fantasies of the Supreme Map Maker. For instance, according to the system set by the Supreme Map Maker, Empire Earth Meridian 0 are all nations cut by the zeroth meridian on Earth. This is not necessarily the same system used locally on each planet, for instance the zeroth meridian goes through Stockholm in this system. Knowledge of geography, politics or culture can actually be an obstacle on your way to victory in this challenge! However, sometimes (actually, most of the time) you can gure out the answer to a quiz question just by looking at the alternatives. Being a low budget show, the underpaid quiz question authors strive to minimize their effort in coming up with the alternatives for each question. They construct each alternative by making a small number of changes to the correct answer, where a change consists of replacing one part of the correct answer with something else. For example, transforming green, blue, stripes into green, yellow, stripes has one single change, while changing the same answer into life, universe, stripes has two changes. The question authors never permute the parts, so order matters. In other words, transforming green, blue, stripes into stripes, blue, green has two changes even though they are both technically the same answer. Note that the answers are case sensitive, so green, blue, stripes and Green, Blue, Stripes need 3 changes. Your task is to write a program that automatically nds the most likely answers to questions constructed in this way. Dene the incongruousity of an alternative as the maximum number of changes needed to transform that alternative into any of the other alternatives. We then seek the alternative(s) with the smallest incongruousity.
PMS 657U 100% PMS 657U 30%

SVART 100%

Task
Given a question and a set of potential answers to it, nd the answer that is easiest to change into any other answer.

Input
The rst line is the question to be answered. The next line contains one positive integer 1 N 100, giving the number of answer alternatives. The next N lines contain one alternative each. The alternatives are lists of parts, separated by a comma and a space. All answers have the same number of parts, at most 100. All parts are strings of letters a-z and A-Z, digits 0-9 and spaces. Each part doesnt contain leading or trailing spaces (except the space after a KTH Challenge 2013 Problem I: Flag Quiz 17 This work by KTH CSC is licensed under a Creative Commons Attribution-Share Alike 2.5

KTH Challenge 2013


comma that separates 2 parts). The maximal length of a part is 50 characters.

Output
Output the alternative that requires the smallest maximum amount of changes to be turned into any other answer. If there are several least incongruous alternatives, output them all in the same order as in the input. Sample Input 1 The flag of the empire Angola? 4 Green stripe, black stripe, yellow Red stripe, black stripe, yellow Red stripe, black stripe, white Red stripe, green stripe, yellow
PMS 657U 30%

SVART 100%

PMS 657U 100%

Sample Output 1 Red stripe, black stripe, yellow Sample Input 2 The flag of the Knights who say Ni? 4 Black, white, pink, shrubbery Black, white, red, shrubbery Pink, white, red, shrubbery Black, pink, red, shrubbery Sample Output 2 Black, white, red, shrubbery

KTH Challenge 2013 Problem I: Flag Quiz 18 This work by KTH CSC is licensed under a Creative Commons Attribution-Share Alike 2.5

Você também pode gostar