Sei sulla pagina 1di 11

ACM International Collegiate Programming Contest, The 2017 Girls Code II Collegiate Programming Contest

(2017)
International University of Rabat, March, 18, 2017
Problem A. Christmas biscuits
Input file: standard input
Output file: standard output
Time limit: 2 seconds
Memory limit: 64 megabytes

Aziza is preparing biscuits for Christmas. Using her rolling pin she is now rolling a dough (see image
below) that she is going to cut into N cylindrical pieces each having a base area of A cm2 . Aziza wants
to know what is the maximum number of biscuits that she can get if the thickness of the dough is 1 cm.
Please help Aziza calculate this number.

Input
The first line of input gives the number of test cases T (T ≤ 10). Each test case is described by two
numbers, S the total area of the dough and A, the base area of a single biscuit.
All areas are in cm2 .

Output
For each test case print, on a separate line, one integer: the maximum number of biscuits that Aziza can
get.

Example
standard input standard output
2 2
10.0 5.0 3
7.0 2.0

Page 1 of 11
ACM International Collegiate Programming Contest, The 2017 Girls Code II Collegiate Programming Contest
(2017)
International University of Rabat, March, 18, 2017
Problem B. Girls Encipher Too
Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 64 megabytes

Kaoutar is an easy going girl who just managed to learn "Ceasar Cipher". Now she wants to show off
how geeky she is to her friends, thus she taught them a slight variant of "Ceasar Cipher"made by her.
First they decide a number N and then take each character of a certain string and shift it to the right by
N only if the index of the character is either a multiple of three or two (Note that shifting is circular,
which means if N = 1, ”z” will become ”a”). If the character is a ”@” and its index is a multiple of 2 or
3, this character will not be shifted but will be replaced with ”#”.

Input
The first line of input contains the number of test cases T (T ≤ 103 ). The first line of each test case
contains two integers N, L (1 ≤ N ≤ 26, 4 ≤ L ≤ 103 ), the number to shift by, and the length of the
string. The next line contains a string S of length L.

Output
For each test case, print on a separate line, the resulting string after applying the algorithm.

Example
standard input standard output
1 zyb#cbe
2 7
xyz@abc

Note
Note that the characters’ index is 0-based and that the input string is guaranteed to be lowercase ascii
alphabetical characters and ”@” ([@a − z])

Page 2 of 11
ACM International Collegiate Programming Contest, The 2017 Girls Code II Collegiate Programming Contest
(2017)
International University of Rabat, March, 18, 2017
Problem C. Oh Numbers
Input file: standard input
Output file: standard output
Time limit: 2 seconds
Memory limit: 64 megabytes

An Oh Number is a positive integer having an odd number of 1-bits in its binary representation. You will
be given a list of numbers. Your task is to check for each of them if it is an Oh Number or not.

Input
The first line of input gives the number N (1 ≤ N ≤ 105 ) of integers to check. N lines follow each
containing a positive number x ≤ 109 .

Output
The output is a single binary string where the ith position in this string is a 1 if the ith integer in the
input is an Oh Number and 0 otherwise.

Example
standard input standard output
5 10110
1
15
28
100001
28374

Page 3 of 11
ACM International Collegiate Programming Contest, The 2017 Girls Code II Collegiate Programming Contest
(2017)
International University of Rabat, March, 18, 2017
Problem D. March the 8th
Input file: standard input
Output file: standard output
Time limit: 2 seconds
Memory limit: 64 megabytes

International Women’s Day is celebrated on March 8 every year in many countries around the world. It is
a day when women are recognized for their achievements without regard to divisions, whether national,
ethnic, linguistic, cultural, economic or political.
We want to know for a given year, the name of the day that corresponds to the 8th of March of this year.

Input
The first line of the input contains the number of test cases T (1 ≤ T ≤ 100).
Each test case is denoted by a single integer Y that corresponds to a year (1000 ≤ Y ≤ 10000).

Output
For each test case, output one line : the name of the day that corresponds to the 8th of march of Y .
In case you were an alien, the names of earth’s weekdays are : Monday, Tuesday, Wednesday, Thursday,
Friday, Saturday and Sunday.

Example
standard input standard output
3 Friday
2019 Tuesday
2016 Wednesday
2017

Note
To simplify the problem, we consider leap years the years that are multiples of 4.

Page 4 of 11
ACM International Collegiate Programming Contest, The 2017 Girls Code II Collegiate Programming Contest
(2017)
International University of Rabat, March, 18, 2017
Problem E. Mountains and Valleys
Input file: standard input
Output file: standard output
Time limit: 3 seconds
Memory limit: 64 megabytes

You will be given a sequence of points in the xy plane. Your task is to check if the given sequence forms
mountains and valleys or not. Here is an example of a sequence of points that forms mountains and valleys:

In general, a sequence of points is said to form mountains and valleys if the first point and the second
point form a segment which has positive slope; the second point and the third point form a segment which
has negative slope, and so on. Slopes keep alternating between positive and negative (infinite slopes are
not allowed). Note that in a valid sequence of mountains and valleys, the first slope should be positive
and the last slope should be negative. So you should check for that too.

Input
The first line of input contains the number of test cases T (T ≤ 10). The first line of each test case
contains the number of points N (3 ≤ N ≤ 105 ). N lines follow each containing a pair of coordinates
(x, y) where −109 ≤ x, y ≤ 109 . N is guaranteed to be an odd number.

Output
For each test case print, on a separate line, "Mountains and Valleys"if the input describes a series of
points that form mountains and valleys. If that is not the case then print "Not Mountains and Valleys".
The strings should be printed without the quotes and they should be printed exactly as given (output is
case sensitive).

Example
standard input standard output
1 Mountains and Valleys
3
-1 -1
1 3
5 1

Page 5 of 11
ACM International Collegiate Programming Contest, The 2017 Girls Code II Collegiate Programming Contest
(2017)
International University of Rabat, March, 18, 2017
Problem F. Counting Inversions
Input file: standard input
Output file: standard output
Time limit: 3 seconds
Memory limit: 64 megabytes

You will be given a sequence, S, of integers of length N . The elements of the sequence are
S[1], S[2], . . . S[N ]. An inversion in the sequence S is a pair of positions i, j satisfying i < j and S[i] > S[j].
In other words, the numbers S[i], S[j] are out of order. Your task is to count the number of inversions in
a given sequence. Your program will be tested on multiple test cases.

Input
The first line of input contains the number of test cases T (T ≤ 10). The first line of each test case contains
an integer N (1 ≤ N ≤ 103 ), the length of the sequence. The next line contains N space separated integers
(−109 ≤ S[i] ≤ 109 ).

Output
For each test case, print on a separate line, the number of inversions.

Example
standard input standard output
2 3
3 5
7 4 -1
5
1 7 3 19 -5

Page 6 of 11
ACM International Collegiate Programming Contest, The 2017 Girls Code II Collegiate Programming Contest
(2017)
International University of Rabat, March, 18, 2017
Problem G. Rima’s Bracelets
Input file: standard input
Output file: standard output
Time limit: 2 seconds
Memory limit: 64 megabytes

Rima’s talent is making bracelets, she always gifts hand-crafted bracelets to her friends. Her favorite colors
are red and blue; she believes that red and blue make for beautiful bracelets. The birthday of Rima’s best
friend is getting closer and she wants to make new bracelets for her. She came up with the following rules
for making those bracelets:

• The number of pieces should be N .

• A piece can be either red or blue.

• The pieces should be placed so that no three pieces of the same color are equally spaced.

The figure on the left is an example of an invalid placement of 8 pieces (3 equally spaced pieces are shown
below) and the figure on the right is an example of a valid placement of 8 pieces.

Input
The first line of input contains the number of test cases T (T ≤ 20). T lines follow each containing an
integer N (1 ≤ N ≤ 20), the number of pieces in the bracelet.

Output
For each test case print, on a separate line, the number of valid bracelets of length N .

Example
standard input standard output
1 6
8

Note
Bracelets in this problem are not circular. They are chains.

Page 7 of 11
ACM International Collegiate Programming Contest, The 2017 Girls Code II Collegiate Programming Contest
(2017)
International University of Rabat, March, 18, 2017
Problem H. Lovely Primes
Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 64 megabytes

It’s Hanane’s birthday, 18th March, and everyone who can code is invited to her party. She’s awaiting
many special gifts today.
Well, the bad news is that her best friend Amal just happened to forget about the birthday. She has got
less than 12 hours to choose between many many accessories as gifts for Hanane. Each accessory is denoted
by a number, and Amal is so confused since she knows that Hanane is in love with prime numbers, thus
she decided to restrict the number of accessories to two, the first and the last accessories encountered
which are denoted by a prime number.

Input
The first line of input contains the number of test cases T (T ≤ 10). The first line of each test case
contains an integer N (1 ≤ N ≤ 103 ), the length of the list. The next line contains N space separated
integers (1 ≤ A[i] ≤ 105 ) denoting the accessories’ numbers.

Output
For each test case, print on a separate line, the index of the first chosen accessory and the index of the
last chosen accessory separated by a space. If there’s no such case, print "−1"(without the quotes).

Example
standard input standard output
4 2 7
10 -1
1 3 18 4 5 6 7 8 9 10 1 5
4 1 1
49 6 12 10
5
3 1 2 1 3
1
11

Note
Note that the first and the last accessories may be at the same index. And that the index is 1-based.

Page 8 of 11
ACM International Collegiate Programming Contest, The 2017 Girls Code II Collegiate Programming Contest
(2017)
International University of Rabat, March, 18, 2017
Problem I. Parent Queries
Input file: standard input
Output file: standard output
Time limit: 4 seconds
Memory limit: 64 megabytes

A perfect binary tree is a binary tree in which every node (except for the leaf nodes) has exactly two
children. The height of such a tree is defined to be the number of levels that it has. For example, a perfect
binary tree of height 1 contains only one node, a perfect binary tree of height 2 contains 3 nodes: the root
and its two children, a perfect binary tree of height 3 contains 7 nodes: the root and its two children, each
of which has two children. We will assume that the nodes of these trees are labeled in post-order. The
following are examples of labeling for heights 1, 2 and 3.

Given a height H (a tree, as described above, can be uniquely determined by its height) and a list of node
labels, you are to find for each of those nodes the label of its parent in the tree. If a node does not have
a parent (i.e., it is the root of the tree) then the parent is assumed to be equal to −1.

Input
The first line of input contains the number of test cases T (T ≤ 10). The first line of each test case
contains two integers H (1 ≤ H ≤ 30) and N (1 ≤ N ≤ 105 ) where H is the height of the tree and
N is the number of queries. The next line contains N space separated integers Qi (1 ≤ Qi ≤ 2H − 1)
representing the queries to answer.

Output
For each test case print, on a separate line, N space separated integers representing the answers to the
queries of that case.

Example
standard input standard output
1 6 -1 3
3 3
5 7 2

Note
A post-order labeling can be done by first labeling the left tree (recursively) and then labeling the right
tree (recursively) and then labeling the root.

Page 9 of 11
ACM International Collegiate Programming Contest, The 2017 Girls Code II Collegiate Programming Contest
(2017)
International University of Rabat, March, 18, 2017
Problem J. Female Managers
Input file: standard input
Output file: standard output
Time limit: 2 seconds
Memory limit: 64 megabytes

It is very common in world’s largest IT companies to have more female project managers. Women have
many natural talents that make them more successful project managers and distinguish them from their
male colleagues. Organizational spirit is one of these qualities of women project managers that is an
important key to the success of a business. The objective of this problem is to measure how good is your
organizational spirit: Given a project that consists of a list of tasks to perform and dependencies among
those tasks, your task, shall you accept it, is to calculate the minimum duration of this project, i.e., the
minimum amount of time it takes to finish all of the tasks.

Input
The input consists of multiple test cases. The first line of the input contains the number of test cases T
(1 ≤ T ≤ 100).
The first line of each test case consists of two integers N , the number of dependencies, and M , the number
of tasks. It is guaranteed that (0 ≤ N, M ≤ 1000).
Then follow N lines each containing two integers: a and b, which means that task a has to be completed
before starting task b (0 ≤ a, b < M ).
Then follows one line containing M integers di : the duration it takes to finsh task i (0 < di ≤ 1000).
It is guaranteed that the input graph is a DAG (Directed Acyclic graph). So there will be no cyclic
dependencies.

Output
For each test case output one integer: the minimum amount of time it takes to finish the project.

Example
standard input standard output
1 13
6 6
4 1
4 0
5 0
5 2
1 3
2 3
1 2 3 4 5 6

Page 10 of 11
ACM International Collegiate Programming Contest, The 2017 Girls Code II Collegiate Programming Contest
(2017)
International University of Rabat, March, 18, 2017
Problem K. Save Humanity !
Input file: standard input
Output file: standard output
Time limit: 2 seconds
Memory limit: 1024 megabytes

Researchers at the Moroccan Academy of Chemistry and Microbiology (MACM) identified a new type
of bacteria capable of killing a human in just few days ! The most dangerous thing is that the number
of these bacteria is multiplying at a frightening rate: generation N will be capable of exterminating the
entire human civilization in few days !
Scientists figured out the mathematical equation behind the reproduction of these bacteria: if the number
of bacteria of generation i is Ui then we have :

Ui = 28Ui−1 − 175Ui−2 + 300Ui−3 for i ≥ 4.

Fortunately, researchers found a way to stop this treat: if n is the newest generation of bacteria, a dosage
of Un nano-liters of penicillin can make a human immune to the diseases caused by these bacteria.
Biologists are not good at computer programming, can you please help them calculating the number of
bacteria of generation n ? Humanity is counting on you !

Input
The input consists of multiple test cases. The first line of the input contains the number of test cases T
(1 ≤ T ≤ 100).
Each test case consists of four integers A, B, C, n. A, B and C are the number of bacteria of generations
3, 2 and 1 respectively (0 ≤ A, B, C ≤ 106 ) and n is the index of the newest generation of bacteria ( 4 ≤
n ≤ 1012 ).

Output
For each test case output one line containing the number of bacteria of generation n.
This number can be very large, so print it modulo 1000000007.

Example
standard input standard output
1 4409
1 1 1 5

Page 11 of 11

Potrebbero piacerti anche