Sie sind auf Seite 1von 15

Pgina 1 de 15

Real Contest Problem Set


The 2013 ACM ICPC in ESCOM IPN

Problems Authors:
Christian Adn Hernndez Snchez (ESCOM-IPN, Mxico)
Ramrez Ibarra Jair (ESCOM-IPN, Mxico)

May 24, 2013


Pgina 2 de 15

A. Satisfaction problem
Description
Maria is running a startup. She is very confident in herself and a very smart leader. She was so
successful in this new project that she has now plenty of customers and she was able to fully satisfy
the needs and expectations of them. But things are getting out of control since the number of
customers has increased astonishingly during the last week. Now she knows that it will be impossible
to satisfy all of her customers so she is asking for help desperately.
What her business does is to find anxious people that want to dance with someone but have never
found a good mate. So this startup collects information from their customers, analyzes it and selects
the best match for a specific customer from all the other customers. Each customer is assigned a
number K based on the analysis results. It is well known that a man will be a perfect match for a
woman if his assigned number divides exactly the assigned number of that woman.
Maria has asked you to help her decide which customers satisfy and which customers not, so that the
number of satisfied customers is maximized. A satisfied customer is the one that got a mate to dance
with. You can only make couples of a man and a woman.

Input
The first line contains an integer T that indicates the number of test cases.
The first line of each test case contains two integers N and M where N is the number of women and
M is the number of men and N+M is the total amount of customers.
The second line of each test case contains N integers where the i-th integer represents the number K
assigned to the i-th woman based on the analysis.
The third line of each test case contains M integers where the i-th integer represents the number K
assigned to the i-th man based on the analysis.

Output
You must print a single line for each test case. In each line you must print an integer that represents
the maximum number of satisfied customers.

Example
Input Output
1
2 3
2 3
2 3 5
2


Limits
1 <= T, N, M <= 1000

Pgina 3 de 15

B. Basic Usernames

FerretSec is a group in charge of identifying hipsters that pretend to belong to Anonymous, but are
not truly hacktivists. With such huge task to fulfill, they take their usernames very seriously. They
think that 1337 is disgusting (and only appropriate for hipsters), so their guidelines for usernames are:
Only lowercase characters.
_ is allowed.

They determine the strength of their usernames according to the actual value of the username as if it
was a valid word in Scrabble. The value of each letter in Scrabble is given by the next table:


1 Point 2 Points 3 Points 4 Points 5 points 8 Points 10 Points
A, E, I, O, N,
R, T, L, S, U
D, G B, C, M, P F, H, V, W,
Y
K J, X Q, Z

The _ character gives no strength to the username. E.g. FerretSec and Ferret_Sec have both a
strength of 14.

This group has a very important mission, so spending time writing usernames is not what they like the
most, so they prefer a short username over a long one if they have the same strength. E.g. FXG is
prefered over FerretSec, even though both have the same strength.

Every single member of FerretSec should know how to type according to the Touch Type method
(using QWERTY; refer to picture 1), so they would rather have a username than can be typed using
only one hand than a username that needs both hands. E.g. FXG is prefered over FJD.

Picture 1. Touch Type method hand disposition

Input
The first line contains an integer T that indicates the number of test cases. Then T cases follow.


Pgina 4 de 15

The first line of each case contains an integer N indicating the number of usernames. Then N lines
follow, each one containing only one username using only lowercase characters and _.

Output

One line for each case, with the best username of the set of N. The best username is the one with the
highest strength and most prefered over the others in the set. It is guaranteed that there will be only
one correct answer.

Example
Input Output
3
2
escom_ipn
isc
3
jan_jones
jqz
jnjn
3
zaz
qoq
jearx

escom_ipn
jqz
zaz


Limits
1 <= T, N <= 1000
1 <= Length of Usernames <= 50



Pgina 5 de 15

C. Computer University
Description
It is very well known that you can get a PhD in Computer Science in the Computer University if you
follow the correct strategy. To get a PhD in Computer Science you need to pass through several
courses. In the Computer University you take a course at a time, this means that you are not allowed
to take two or more courses simultaneously and that there is a predefined order in which you have to
take each course.

At the very beginning you start with energy 0. To be able to take the course Ci you need to have at
least energy Ei. Before taking the course Ci you have two options. The first one is to take a candy
that will provide you a value Ei of energy so that at the end of the course you will have an energy
value of E + Ei where E is your energy value before taking the candy. The second option is not to
take the candy, but your energy value will decrease Ei units at the end of the course, so that when
you complete the course Ci you will have an energy value of E Ei. Remember that you cannot take
the course Ci if you have less than Ei of energy, As you might guess, if you have less than Ei of
energy before taking a course you have just one option, you must take the candy. For example, since
you have energy 0 before taking the first course you need to take the first candy, and at the end of
the course you will have energy E + E1 = E1 where E1 is the value of energy provided by the first
candy.

Find a strategy in which you take the minimum amount of candies and you still can get a PhD in
Computer Science at Computer University, it means you take all of the courses.

Input
First line contains an integer T that specifies the number of test cases.
The first line of each test case contains an integer N that specifies the number of classes that you
have to take in order to get a PhD in CS.

The second line of each test case contains N integers. The i-th integer indicates the energy value Ei
that you must have before taking the i-th course. You must take the courses in the order in which
they appear. It means that you cannot take the i-th course if you have not taken the (i-1)-th course.
You do not have to take any course in order to take the first course.

Output
You must print a single line for each test case. In each line you must print a single integer that
indicates the minimum number of candies that you must eat in order to take all of the courses.




Pgina 6 de 15



Example
Input Output
1
3
4 2 6
1


Limits
1 <= N <= 20
1<= T <= 20
1 <= Ei <= 100


Pgina 7 de 15

D. Did you mean: Accepted?

An anonymous Llama has an online store, but his store lacks of a Did you mean: XXX? feature. He
has been researching how to do such a thing, and has defined a way to implement such a thing:

1 First, he counts the occurrences of each word he has in the descriptions of the products in the
store.
2 Then, when the user mistype a word, he gets all the words that are similar (guesses) to that
mistyped word.
3 From that set of words, he chooses the word that appears more times in the descriptions of the
products, and proposes that word as a possible correction.

It is said that a word is similar to a second word, if you only need to apply 2 transformations to the
first word to get the second. The possible transformations are:

1 Add a character to whichever position in the word.
2 Remove any character in the word.
3 Convert character to any other character in the word (e.g. a => d).

Input
The first line contains an integer T that indicates the number of test cases. Then T cases follow.

The first line of each case contains an integer M indicating the number of distinct words contained in
the description of the products. Then M lines follow, each one containing only one word composed of
only lowercase letters and the number of ocurrences, both values separeted with a blank space.

The next line will contain an integer N with the number of the words to check. Then N lines will follow,
each one containing only one word that could or could not be mistyped.

Output
For each word to check, you must print a single line with the answer: If the word exists in the set of
words that exist in the description of the products, you must print Correct, otherwise you should print
Did you mean: X? where X is the possible correction according to the algorithm described above; If
the word is not similar (following the criteria above) to any of the of words that exist in the description
of the products you must print Incorrect. You should print a blank line after each case.





Pgina 8 de 15



Example
Input Output
2
2
hello 5
world 10
3
hell
world
goodbye
4
love 54
loved 62
loving 32
beloved 4
3
loved
luve
lube

Did you mean: hello?
Correct
Incorrect

Correct
Did you mean: loved?
Did you mean: love?


Limits
1 <= T <= 10
1 <= Length of Words <= 10
1 <= N <= 100000
1 <= M <= 100000




Pgina 9 de 15

E. Emerald

In the Northsouthy territories there is a place where you can find Emeralds. The Southnorthy
company wants to get the highest amount of emeralds possible. The terrain is represented as a
matrix of M rows by N columns, and in each cell there is a number with the final profit of detonating
that cell in order to get emeralds (note that it is possible that some cells have negative profit).

The company has permission for only one detonation, no matter the size, but it must be a rectangle
with sides parallel to the axes. You were hired to know what is the maximum profit that could be
achieved.

Input

The first line contains an integer T that indicates the number of test cases. Then T cases follow.

The first line of each case contains two integers M and N. Then M lines follow, each one containing N
integers representing the terrain.

Output

For each case, you must print a single integer, that is the maximum profit that can be achieved with
the given conditions.

Example
Input Output
1
4 4
1 2 3 4
-4 -3 -2 -1
1 2 3 4
-4 -3 -2 -1
12


Limits
1 <= T <= 10
1 <= M, N <= 1000





Pgina 10 de 15

F. Future kingdom
Description
The king of ESCOM has been very busy trying to make his kingdom more wonderful. He has decided
to transform many buildings and streets and it has to be done as soon as possible since the king is a
little impatient when things do not look beautiful. One of the things he wants to change is his
transportation network.

This network is made of stations and roads and it has a tree structure, it means that there are N-1
bidirectional roads that connect the N stations that exist in the network and that you can reach every
station from any station that you want, since any pair of stations in the network is connected by a set
of roads.

The king of ESCOM wants to delete some stations in the network because it is getting inefficient, but
he wants to spend as less money as possible. To achieve this, the king will pick a set of stations,
delete them and of course, he will delete every road that connects those stations to the stations that
will not be deleted. Finally, he wants the remaining stations to be still connected so that he does not
have to add more roads to reconnect the network.

The king of ESCOM has asked you to help him find the number of ways that you can delete stations
so that all of the stations in the new network remain connected. You can delete all of the stations or
decide to delete no station.

Input
The first line contains an integer T that represents the number of test cases.
The first line of each test case contains an integer N that represents the number of stations in the
network.
The following N-1 lines in each test case contains two integers A, B separated by spaces that
indicate that there is a bidirectional road between station A and station B.

Output
You must print a single line for each test case. In this line you must print a single integer that
represents the number of ways that you can delete a certain number of stations under the described
circumstances.







Pgina 11 de 15

Example
Input Output
1
3
1 2
1 3
7

Limits
1 <= N <= 10000
1 <= A, B <= N
1 <= T <= 1000

Pgina 12 de 15

G. Give me more chocolate
Description
Pedro is a big fan of chocolate. He eats as much chocolate as he can, but recently he had a health
problem and his doctor told him that its time to decrease the amount of chocolate bars that he eats,
otherwise he will end up dying.

This statement scared Pedro so much, that he decided he would continue eating chocolate on a daily
basis, but he would eat only two chocolate bars per day. Now he selects the chocolate bars he will
eat in the next N days and sets their quality value. Pedro has many chocolate bars with random
quality values and he would like to pick them so that he eats a balanced quality of chocolate every
day. The quality value of chocolate in a specific day is the sum of the quality of the two chocolate bars
that Pedro eats that day. He has asked you to reorder the chocolate bars so that the difference
between the day with the maximum quality value of chocolate and the day with the minimum quality
value of chocolate is minimized.

Input
First line contains an integer T that indicates the number of test cases.

The first line of each test case contains an integer N that indicates the number of chocolate bars that
Pedro will eat in the following N/2 days. You can assume that N will always be an even number.

The second line of each test case contains N integers separated by space. The i-th integer indicates
the quality value q
i
of the i-th chocolate bar that Pedro will eat.

Output
You must print a single line per test case. In each line you must print an integer that indicates the
minimum difference between the day with the maximum quality value of chocolate and the day with
the minimum quality value.

Example
Input Output
3
4
2 6 4 3
6
1 1 1 1 1 1
8
4 2 4 2 1 3 3 7
1
0
2




Pgina 13 de 15


Limits
1 <= T <= 1000
2 <= N <= 100
1 <= q
i
<= 10000


Pgina 14 de 15

H. HTML Entities

Fernando the ferret is working with HTML; one of the things he hates the most is that nasty Canvas
tag. He is in that point when all the HTML coders need to have some arbitrary polygons in their
pages. Since he hates the Canvas tag, he has developed a way to draw whatever he wants with a
simple trick: You can simulate a drawn line with a Div of height 1, without borders or margin, with
absolute positioning, and a given background color.

Since he wants to create polygons, he first defines the coordinates of the polygon he wants, then he
creates the div according to the borders of the polygon and sets the css properties needed to achieve
its goal (top, left, width, and the rotation transform). At this point he only wants to create convex
polygons (every internal angle is less than or equal to 180 degrees):



That method works, but other problem has arisen: he also wants to fill the polygons with a
background color. He knows he can create more divs to simulate the background color in the
polygon, he uses the same function to create these filling divs and the perimeter divs, so the filling
divs will be always of height 1; but since he is a sensible programmer, he knows that that will
decrease the performance of the pages significantly, so he wants to minimize the number of inner
divs needed to fill the polygon.

Input
The first line contains an integer T that indicates the number of test cases. Then T cases follow.

The first line of each case contains an integer N indicating the number of points in the polygon. Then
N lines follow, each with 2 integers, the X and Y coordinates of the ith point of the polygon. The
points will be always given in clockwise order.


Pgina 15 de 15



Output
For each case, you must print a single integer indicating the minimum number of divs needed to
create the polygon and fill it with a background color using the method described above. This number
must be the sum of the perimetric divs and the filling divs.

Example
Input Output
1
4
0 50
50 50
50 0
0 0
53


Limits
1 <= T, N <= 1,000
0 <= X, Y <= 1,000,000

Das könnte Ihnen auch gefallen