ACM Octubre 2014
ACM Octubre 2014
$ /%'0%,1,*#'-
a) Displays
Basename: Displays
Description
A seven segment display, similar to the one shown on the right, is
composed of seven light-emitting elements. Individually on or off, they
can be combined to produce 127 different combinations, including the
ten Arabic numerals. The figure on the next page illustrates how the
ten numerals are displayed. 7-seg displays (as theyre often
abbreviated) are widely used in digital clocks, electronic meters, and
calculators. A 7-seg has seven connectors, one for each element, (plus
few more connectors for other electrical purposes.) Each element can
be turned on by sending an electric current through its pin. Each of the
seven pins is viewed by programmers as a single bit in a 7-bit number,
as they are more comfortable dealing with bits rather than electrical
signals. The figure on the right shows the bit assignment for a typical 7-
seg, bit 0 being the right-most bit. For example, in order to display the
digit 1, the programmer knows that only bits 1 and 3 need to be on, i.e.
the 7-bit binary number to display digit 1 is 0001010, or 10 in decimal.
Lets call the decimal number for displaying a digit, its display code, or
just code for short. Since a 7-seg displays 127 different configurations,
display codes are normally written using 3 decimal places with leading
zeros if necessary, i.e. the display code for digit 1 is written as 010.
In a 9-digit calculator, 9 7-seg displays are stacked next to each other,
and are all controlled by a single controller. The controller is sent a
sequence of 3n digits, representing n display codes, where 0 < n < 10.
If n < 9, the number is right justified and leading zeros are
automatically displayed. For example, the display code for 13 is
010079 while for 144 it is 010106106
Write a program that reads the display codes of two numbers, and
prints the display code of their sum.
!"#$% '()*+%
Your program will be tested on one or more test cases. Each test case is
specified on a single line in the form of A+B= where both A and B are display
codes for decimal numbers a and b respectively where 0 < a,b < a + b < 1, 000,
000, 000.
The last line of the input file is the word "BYE" (without the double
quotes.)
,$%#$% '()*+%
For each test case, print A+B=C where C is the display code for a + b.
-+*#./ !"#$%0,$%#$%
!"#$% ,$%#$%
010079010+010079=
106010+010=
010079010+010079=010106106
106010+010=106093
!"#$%&' )#*+',*,-' .$ /%'0%,1,*#'-
BYE
!"#$%&' )#*+',*,-' .$ /%'0%,1,*#'-
12 '()*$.+ ,"/
Basename: '()*$.+
Description
Formula One is the highest class of car racing sports. A typical Formula One season
consists of a series of races called Grands Prix which constructors like Ferrari, Renault,
etc. and others participate with one or more cars driven by the best drivers in the world.
During the season, teams compete in two parallel championships: the drivers
championship and the teams championship.
In the drivers championship, drivers compete to achieve the maximum total number of
points by the end of the season, the rules of the competition states that the top eight
drivers at each Grand Prix receive 10,8,6,5,4,3,2,1 points respectively. In case of points
tie, the driver with the highest number of first places leads. If still tied, then the highest
second places, and so on till the highest 8th places. If still tied, then drivers are sorted
lexicographically by their last and then by their first names.
After each race, the points received by each driver are added to his teams pocket, and at
the end of the season the team with the highest number of points wins the teams
championship. To add excitement to the season, team sponsors are allowed to buy
drivers from other teams even within the same season. In case of points tie between
teams, teams are sorted lexicographically by their names. In this problem, you are given
data of a formula one season and youre asked to process these data according to the
rules above to determine both the drivers and teams standings.
!"#$% '()*+%
Your program will be tested on one or more data-sets, each representing a Formula One
season. All input lines are 255 characters or less. Studying the sample I/O youll discover
that the first line of each season has an integer N, where 0 < N < 32 and representing the
number of Grands Prix in that season. For each Grand Prix, the name of the Grand Prix
appears on a line by itself (maximum length is 64 characters) followed by a table of the
first name, last name and team name of the top eight drivers, from 1 to 8, in that Grand
Prix. Each of the first and last names is a sequence of printable ASCII characters, no
longer than 12 characters, and contains no spaces. Each team name is a sequence of
printable ASCII characters, no longer than 18 characters, and may contain spaces (but no
leading or trailing spaces.) Each team name is followed by a single period . which is not
part of the name. Trailing white space may follow. A line of three -s follows the listing of
each Grand Prix. The last line of the input file contains a single zero.
,$%#$% '()*+%
For each data set in the input you must print Season k: where k is the data-set number
(starting from 1.) The next line must state Drivers Standing:. On subsequent lines list the
drivers standing for that season. For each driver, print their first and last names separated
by exactly one space and left justified in a field of width 25, followed by a single space,
followed by the total number of points achieved by the driver during the season. The
drivers standing should be followed by a blank line.
The next line must state Teams Standing: On subsequent lines list the teams standing
for the that season. For each team, print the team name left justified in a field of width 25,
!"#$%&' )#*+',*,-' .$ /%'0%,1,*#'-
followed by a single space, followed by the total number of points the team has scored
during the season. The teams standing should be followed by a blank line.
-+*#./ !"#$%0,$%#$%
!"#$%
,$%#$%
!"#$%&' )#*+',*,-' .$ /%'0%,1,*#'-
32 4+)5%6
Basename: 4+)5%6
Description
Im out of stories. For years Ive been writing stories, some rather silly, just to make simple
problems look difficult and complex problems look easy. But, alas, not for this one.
Youre given a non empty string made in its entirety from opening and closing braces. Your
task is to find the minimum number of operations needed to make the string stable. The
definition for being stable is as follows:
1. An empty string is stable.
2. If S is stable, then !S" is also stable.
3. If S and T are both stable, then ST (the concatenation of the two) is also stable.
All of these strings are stable: !", !"!", and !!"!""; But none of these: "!, !!"!, nor !"!.
The only operation allowed on the string is to replace an opening brace with a closing
brace, or visa-versa.
!"#$% '()*+%
Your program will be tested on one or more data sets. Each data set is described on a
single line. The line is a non-empty string of opening and closing braces and nothing else.
No string has more than 2000 braces. All sequences are of even length.
The last line of the input is made of one or more - (minus signs.)
,$%#$% '()*+%
For each test case, print the following line:
k.N
Where k is the test case number (starting at one,) and N is the minimum number of
operations needed to convert the given string into a balanced one.
-+*#./ !"#$%0,$%#$%
!"#$% ,$%#$%
}{
{}{}{}
{{{}
---
1. 2
2. 0
3. 1
!"#$%&' )#*+',*,-' .$ /%'0%,1,*#'-
72 895": + "$*1/)
Basename: 895":
Description
Number guessing is a popular game between elementary-school kids. Teachers
encourage pupils to play the game as it enhances their arithmetic skills, logical thinking,
and following-up simple procedures. We think that, most probably, you too will master in
few minutes. Heres one example of how you too can play this game: Ask a friend to think
of a number, lets call it n
0
.
Then:
1. Ask your friend to compute n
1
= 3 $ n
0
and to tell you if n
1
is even or odd.
2. If n
1
is even, ask your friend to compute n2 = n
1
/2. If, otherwise, n
1
was odd then
let your friend compute n
2
= (n
1
+ 1)/2.
3. Now ask your friend to calculate n
3
= 3 $ n
2
.
4. Ask your friend to tell tell you the result of n
4
= n
3
/9. (n
4
is the quotient of the
division operation. In computer lingo, / is the integer-division operator.)
5. Now you can simply reveal the original number by calculating n
0
= 2 $ n
4
if n
1
was
even, or n
0
= 2 $ n
4
+ 1 otherwise.
Heres an example that you can follow: If n
0
= 37, then n
1
= 111 which is odd. Now we can
calculate n
2
= 56, n
3
= 168, and n
4
= 18, which is what your friend will tell you. Doing the
calculation 2 n
4
+ 1 = 37 reveals n
0
.
!"#$% '()*+%
Your program will be tested on one or more test cases. Each test case is made of a single
positive number (0 < n
0
< 1, 000, 000).
The last line of the input file has a single zero (which is not part of the test cases.)
,$%#$% '()*+%
For each test case, print the following line:
k.BQ
Where k is the test case number (starting at one,) B is either even or odd (without the
quotes) depending on your friends answer in step 1. Q is your friends answer to step 4.
-+*#./ !"#$%0,$%#$%
!"#$% ,$%#$%
37
38
0
1. odd 18
2. even 19
!"#$%&' )#*+',*,-' .$ /%'0%,1,*#'-
/2 ;().7 3$# <$=5+
Basename: ;().7
Description
FIFA is considering a few changes to the way it organizes the Football World Cup.
Currently,32 teams compete for the World Title in two stages. During the first stage, known
as the groups stage, the 32 teams are split evenly into 8 groups. Every team in the group
plays 3 games, one against each team in their own group. Teams are then ranked within
their group according to some points system. During the second (and final) stage, the top
two teams from each group advance to the knockout stage where eight games are played
to determine eight winners who would then play four games to determine four winners,
then two games to determine the two winners who would then play the final game to
determine the world champion. Needless to say, for the knockout stage to work, the
number of teams in that stage has to be a power of two.
FIFA is considering adding more groups, adding more teams to groups, and possibly
changing the number of teams advancing from each group to the knockout stage. In
addition, FIFA is considering having certain teams (previous champion, host country, etc.)
advance to the knockout stage directly (without having to play in the groups stage.) But
FIFA needs to know how many games will be played if any of these changes are applied.
Please help them!
!"#$% '()*+%
Your program will be tested on one or more test cases. Each test case is specified on a
single line made of 4 natural numbers with the following format:
G T A D
Where (G > 0) is the number of groups; T is the number of teams in each group; A is the
number of teams advancing from each group to the knockout stage; and D is the number
of teams directly advancing to the knockout stage without going through the groups stage.
Note that (0 < A T) and that the four numbers in the input are no larger than 2
16
.
If the total number of teams in the knockout stage is not a power of two, your program
must increase them to the closest power of two.
The last test case is followed by a dummy line made of four -1s.
,$%#$% '()*+%
For each test case, print:
G*A/T+D=X+Y
where G, A, T, and D are as in the input, X is the total number of games, and Y is the
number of teams your program determined it must add.
-+*#./ !"#$%0,$%#$%
!"#$% ,$%#$%
8 4 2 0
8 4 2 1
-1 -1 -1 -1
8*2/4+0=63+0
8*2/4+1=79+15
!"#$%&' )#*+',*,-' .$ /%'0%,1,*#'-
>2 ?. @)+" +3()7/A"
Basename: B3()7/("
C/=3)5#35A"
"#$%& '& () *' +&,(' -*. /0122#'3( 4*( 516#-&)7 82 4*1(0( $&-9(310 $&' )* #-16& :#'$%13&7 9#0#
%#$(02& ,(0 -;) &2,15#51<& 4*( 82= "#$%& >&0-*2? *' #$&05(?' $&' 2&) '&-/0() 5( 2&) 9#@)() . )*)
$#913#2()7 (' 51$%& #$&05(?' 0(61)30& 2&) '&-/0( 5( 2&) 9#@)() . )*) 0()9($31,#) $#913#2()= "#$%&
4*1(0( 90(6*'3#02( # :#'$%13& 2&) 9#@)() 9#0# 4*( :#'$%13& 2( 1'514*( 2# $#913#27 . ,(0 )1 ()3( A231-&
90&9&0$1&'# 2# 0()9*()3# $&00($3# & 1'$&00($3#=
B#2( 2# 9('# -('$1&'#0 4*( :#'$%13& )( )#/( -*$%&) 5( 2&) 9#@)() 5(2 #$&05(?' 5( "#$%&7 .
"#$%& )( )#/( 2&) '&-/0() 5( ,#01&) 9#@)() C9(0& '& '($()#01#-('3( 2#) $#913#2() 5( 3&5&) (22&)D .
2( 4*1(0( 90(6*'3#0 # :#'$%13& )1' 0(,1)#0 (2 #$&05(?'7 9&0 3#2 0#<?' (' #26*'#) &$#)1&'() "#$%&
90(6*'3# )&/0( 9#@)() 4*( '& ()3;' (' (2 #$&05(?'=
"#$%& 31('( *' 90&/2(-#7 4*( (2 #$&05(?' 31('( -*$%&) 9#@)() $&-& 9#0# 0($&05#02&) 3&5&)= E
$*#'5& :#'$%13& 0()9&'5( # 2# 90(6*'3# 5( "#$%&7 ()3( A231-& 3#05# 5(-#)1#5& (' ('$&'30#0 (2
9#@) (' (2 #$&05(?' 9#0# 5(3(0-1'#0 )1 2# $#913#2 () $&00($3# & 1'$&00($3#= "#$%& '($()13# 4*( 2(
5()#00&22() *'# #921$#$1?' 4*( 2( 9(0-13# ('$&'30#0 0;915#-('3( (2 9#@) . )* $#913#27 9#0#
5(3(0-1'#0 )1 2#) 0()9*()3#) 5( :#'$%13& ()3;' $&00($3#) & '&= F)@ -1)-& (2 90&60#-# 5(/(0@# 5(
1'51$#02( # "#$%&7 $*#'5& )* -(-&01# >#22( . 2( 90(6*'3( )&/0( *' 9#@) 4*( '& ()3; (' (2
#$&05(?'7 9#0# (,13#0 4*( :#'$%13& 516# 2# 0()9*()3# (' ,#'&7 9&04*( "#$%& '& 9&50; 5(3(0-1'#0
)1 ()3; /1(' & '& 2# 0()9*()3#=
'()*+%( 7/ ?"%)+7+
G# ('30#5# $&')3# 5( *'# )(01( 5( 2@'(#)7 2# 901-(0# 5( (22#) $&'31('( 5&) ('3(0&) 4 . D CH : 7 I
HJ7JJJD7 4 () (2 'A-(0& 5( 9#0(+#) >&0-#5#) 9&0 9#@) $#913#2 C)(9#0#5&) 9&0 ()9#$1&D7 4*( 31('(
"#$%& (' )* #$&05(?'7 D () (2 'A-(0& 5( 9#@)() 4*( "#$%& 2( 90(6*'3# # :#'$%13&= G#) )16*1('3()
4 2@'(#) $&'31('(' 5&) 9#2#/0#) )(9#0#5#) 9&0 *' ()9#$1&7 (2 9#@) . )* $#913#27 $#5# 9#2#/0# 31('(
('30( H . HK $#0#$3(0() C)1' ()9#$1&)D= G#) )16*1('3() D 2@'(#)7 9&50@#' 3('(0 *'# 5( 2#) )16*1('3()
5&) >&0-#)
L&2& *'# 9#2#/0# C(2 9#@) 4*( 90(6*'3& "#$%&D7 (' $#)& 5( 4*( (2 9#@) '& )( ('$*('30( ('
(2 #$&05(?'
M&) 9#2#/0#)C 9#@) 4*( 90(6*'3& "#$%& . 2# $#913#2 4*( $&'3()3& :#'$%13&D
N&5#) 2#) ('30#5#) $*-9210;' $&' 2#) ()9($1>1$#$1&'() -('$1&'#5#) #'3(01&0-('3(= O2 #$&05(?' '&
3('50; 9#@)() 0(9(315&)=
'()*+%( 7/ -+.57+
!"#$%&' )#*+',*,-' .$ /%'0%,1,*#'-
L( 5(/(0;' 1-901-10 D 2@'(#)7 *'# 9&0 $#5# 9#@) 90(6*'3#5& 9&0 "#$%&= L1 (2 9#@) 5( 2# 90(6*'3#
no est en el acorden, se debe imprimir !" $%&"%'()*". Si el pas preguntado est en el
#$&05(?'7 5(/(0; imprimir +,$% si la respuesta es correcta, de otra manera debe imprimir
-)..
?E/*#.(= ?"%)+7+0-+.57+
O'30#5# L#215#
P Q
R0#'$1# :#01)
S(T1$& S(T1$&
U3#21#
S(T1$& S(T1$&
R0#'$1# G&'50()
"& ('$&'30#5&
V1('
S#2