Post on 02-May-2017
Pátzcuaro Michoacán ITSPA Abril 2014 !!
Set Test ACM Junior ITSPA
ACADEMIA DE TICS !!
!1SET TEST
A. Flowers Flourish from France !Fiona has always loved poetry, and recently she discovered a fascinating poetical form.
Tautograms are a special case of alliteration, which is the occurrence of the same letter at the
beginning of adjacent words. In particular, a sentence is a tautogram if all of its words start
with the same letter.
!For instance, the following sentences are tautograms:
• Flowers Flourish from France
• Sam Simmonds speaks softly
• Peter pIckEd pePPers
• truly tautograms triumph
!Fiona wants to dazzle her boyfriend with a romantic letter full of this kind of sentences.
Please help Fiona to check if each sentence she wrote down is a tautogram or not.
!Input
Each test case is given in a single line that contains a sentence. A sentence consists of a
sequence of at most 50 words separated by single spaces. A word is a sequence of at most 20
contiguous uppercase and lowercase letters from the English alphabet. A word contains at
least one letter and a sentence contains at least one word.
!The last test case is followed by a line containing only a single character `*' (asterisk).
!Output
For each test case output a single line containing an uppercase `Y' if the sentence is a
tautogram, or an uppercase `N' otherwise.
!!
!2SET TEST
Sample Input
Flowers Flourish from France
Sam Simmonds speaks softly
Peter pIckEd pePPers
truly tautograms triumph
this is NOT a tautogram
*
!Sample Output
! Y
Y
Y
Y
N!
!
!3SET TEST
B. Squares
!A children's board game consists of a square array of dots that contains lines connecting some of the pairs of adjacent dots. One part of the game requires that the players count the number of squares of certain sizes that are formed by these lines. For example, in the figure shown below, there are 3 squares-2 of size 1 and 1 of size 2. (The ``size" of a square is the number of lines segments required to form a side.)
Your problem is to write a program that automates the process of counting all the possible squares.
Input
The input file represents a series of game boards. Each board consists of a description of a square array of n2 dots (where 2 <= n <= 9) and some interconnecting horizontal and vertical lines. A record for a single board with n2 dots and m interconnecting lines is formatted as follows:
Line 1: n the number of dots in a single row or column of the array
Line 2: m the number of interconnecting lines
Each of the next m lines are of one of two types:
H i j indicates a horizontal line in row i which connects
the dot in column j to the one to its right in column j + 1
or
V i j indicates a vertical line in column i which connects
the dot in row j to the one below in row j + 1
!!4SET TEST
Information for each line begins in column 1. The end of input is indicated by end-of-file. The first record of the sample input below represents the board of the square above.
!Output
For each record, label the corresponding output with ``Problem #1", ``Problem #2", and so forth. Output for a record consists of the number of squares of each size on the board, from the smallest to the largest. lf no squares of any size exist, your program should print an appropriate message indicating so. Separate output for successive input records by a line of asterisks between two blank lines, like in the sample below.
!Samples Input
4
16
H 1 1
H 1 3
H 2 1
H 2 2
H 2 3
H 3 2
H 4 2
H 4 3
V 1 1
V 2 1
V 2 2
V 2 3
V 3 2
V 4 1
V 4 2
!5SET TEST
V 4 3
2
3
H 1 1
H 2 1
V 2 1
Sample Output
Problem #1
2 square (s) of size 1
1 square (s) of size 2
**********************************
Problem #2
No completed squares can be found.
!
!6SET TEST
C. Head or Tail
!John and Mary have been friends since nursery school. Since then, they have shared a playful routine: every time they meet, they play Head or Tail with a coin, and whoever wins has the priviledge of deciding what they are going to play during the day. Mary always choose Head, and John always choose Tail.
Nowadays they are in college, but continue being truly good friends. Whenever they meet, they still play Head and Tail, and the winner decides which film to watch, or which restaurant to have dinner together, and so on.
Yesterday Mary confided to John that she has being keeping a record of the results of every play since they started, in nursery school. It came as a surprise to John! But since John is studying Computer Science, he decided it was a good opportunity to show Mary his skills in programming, by writing a program to determine the number of times each of them won the game over the years.
!Input
The input contains several test cases. The first line of a test case contains a single integer N indicating the number of games played (1 ≤ N ≤ 10000). The following line contains N integers Ri, separated by space, describing the list of results. If Ri = 0 it means Mary won the ith game, if Ri = 1 it means John won the ith game (1 ≤ i ≤ N). The end of input is indicated by N = 0.
!Output
For each test case in the input your program should output a line containing the sentence "Mary won X times and John won Y times", where X ≥ 0 and Y ≥ 0.
!Sample Input
5
0 0 1 0 1
6
0 0 0 0 0 1
0
!
!7SET TEST
Output for the Sample Input
Mary won 3 times and John won 2 times
Mary won 5 times and John won 1 times
!!
!8SET TEST
D. Digits Count
!Diana is going to write a list of all positive integers between A and B, inclusive, in base 10 and without any leading zeros. She wants to know how many times each digit is going to be used.
Input
Each test case is given in a single line that contains two integers A and B (1 <=A<= B <=108). The last test case is followed by a line containing two zeros.
Output
For each test case output a single line with 10 integers representing the number of times each digit is used when writing all integers between A and B, inclusive, in base 10 and without leading zeros. Write the counter for each digit in increasing order from 0 to 9.
Sample Input
19
12 321
5987 6123
12345678 12345679
0 0
Sample Output
0 1 1 1 1 1 1 1 1 1
61 169 163 83 61 61 61 61 61 61
134 58 28 24 23 36 147 24 27 47
0 2 2 2 2 2 2 2 1 1
!!
!9SET TEST
E. Square Number
A square number is an integer number whose square root is also an integer. For example 1, 4, 81 are some square numbers. Given two numbers a and b you will have to find out how many square numbers are there between a and b (inclusive).
Input
The input file contains at most 201 lines of inputs. Each line contains two integers a and b (0<a≤b≤100000). Input is terminated by a line containing two zeroes. This line should not be processed.
!Output
For each line of input produce one line of output. This line contains an integer which denotes how many square numbers are there between a and b (inclusive).
!!
!
Sample Input Output for Sample Input
1 4 2
1 10 3
0 0
!10SET TEST
F. Big Mod Calculate
for large values of B, P, and M using an efficient algorithm. (That's right, this problem
has a time dependency !!!.)
!Input
Three integer values (in the order B, P, M) will be read one number per line. B and P are
integers in the range 0 to 2147483647 inclusive. M is an integer in the range 1 to 46340
inclusive.
!Output
The result of the computation. A single integer.
!
!!
Sample Input
3
18132
17
!17
1765
3
!2374859
3029382
36123
Sample Output
13
2
13195
!11SET TEST
G. Correct Move
We have a square board with 64 places, numbered from 0 to 63, see Figure 1. There are
two pieces: A king and a queen. The pair of king's place and queen's place is called the state.
A state is legal if the pieces are not at the same place. The king and queen move alternatingly.
The king can move one step in a horizontal or vertical direction, as long as it does not arrive
at the place of the queen. The queen can move one ore more steps in a horizontal or vertical
direction, as long as it does not encounter the king. All these moves are called legal. Please
note that the pieces may not move diagonally.
Figure 1.
!For example, suppose we have a state with a king at place 17 and a queen at place 49, as
in Figure 2. The legal moves of the king are to places 9, 16, 18, and 25 and the queen can
legally move to place 25, 33, 41, 48, 50, 51, 52, 53, 54, 55, or 57. We impose, however, an
extra restriction: A piece may not move to a place where the other one can also move to.
Legal moves satisfying this restriction are called allowed. In Figure 2, all possible places the
king and the queen can move to by an allowed move, are denoted with a circle ( ) and a dot ( ),
respectively. In Figure 3, the king cannot move, it is locked in.
!!!
!12SET TEST
!This problem requires you to write a program that does some checking related to the
movement of the queen.
!Input
The input for your program resides in a textfile that ends with the standard end-of-file
marker. Each line ends with the standard end-of-line marker and contains a sequence of three
integers in the range O..63, separated by one space. The first two integers denote the place of
the king and the queen, respectively. Together they form a state. The third integer denotes a
new place for the queen. You may think of it as computed by some function movequeen.
Your program determines whether:
• the given state is legal
• the queen's move is legal
• the queen's move is allowed.
Furthermore, if these requirements are met, your program determines whether the
move of the queen results in a state where the king is locked in.
!Output
The output is also a textflle. For each input line, your program produces one output line
with one of the following messages:
• Illegal state
• Illegal move
•Move not allowed
•Continue
•Stop
!13SET TEST
`Illegal state' indicates that the given state is not legal, i.e. the pieces are at the same
place.
`Illegal move' means that the given state is legal, but the queen's move is illegal.
`Move not allowed' applies if both the given state and the queen's move are legal, but
the queen's move is not allowed.
Both `Continue' and `Stop' mean that the given state is legal and the queen's move is
allowed. If the king can do an allowed move in the resulting state, the message is `Continue',
otherwise the king is locked in and you reply `Stop'.
!Sample Input
! 17 17 49
17 49 56
17 49 9
17 49 17
17 49 25
17 49 33
17 49 41
17 49 49
56 48 49
!Sample Output
!Illegal state
Illegal move
Illegal move
Illegal move
Move not allowed
Continue
Continue
Illegal move
Stop
!
!14SET TEST
H. Burger When Mr. and Mrs. Clinton's twin sons Ben and Bill had their tenth birthday, the party
was held at the McDonald's restaurant at South Broadway 202, New York. There were 20
kids at the party, including Ben and Bill. Ronald McDonald had made 10 hamburgers and 10
cheeseburgers and when he served the kids he started with the girl directly sitting left of Bill.
Ben was sitting to the right of Bill. Ronald flipped a (fair) coin to decide if the girl should have
a hamburger or a cheeseburger, head for hamburger, tail for cheeseburger. He repeated this
procedure with all the other 17 kids before serving Ben and Bill last. Though, when coming to
Ben he didn't have to flip the coin anymore because there were no cheeseburgers left, only 2
hamburgers.
Ronald McDonald was quite surprised this happened, so he would like to know what the
probability is of this kind of events. Calculate the probability that Ben and Bill will get the
same type of burger using the procedure described above. Ronald McDonald always grills the
same number of hamburgers and cheeseburgers.
!Input
The first line of the input-file contains the number of problems n , followed by n times:
!a line with an even number [2,4,6,...,100000], which indicates the number of guests
present at the party including Ben and Bill.
!Output
The output consists of n lines with on each line the probability (4 decimals precise) that
Ben and Bill get the same type of burger.
!Note: a variance of is allowed in the output due to rounding differences.
!Sample Input
!3
6
10
!15SET TEST
256
!Sample Output
!0.6250
0.7266
0.9500
!!
!16SET TEST