Professional Documents
Culture Documents
plot(x,y) stem(x,y)
)
Again our Mr. Motlob only uses two digits 0 and 1 (he says he loves binary
number system but haters say otherwise :p ) . After learning this stem() function he
plots different sequences of 1 and 0 all day long. He was happy, until very recently
he decided to count his plots. But soon it turned to be a very huge number. So he
decided to only plot some certain sequences.
Roughly speaking :
1 ) He will only plot sequences of total length "n"
2) The sequences will only contain "0" or/and "1"
3) He won't put more then "x" 0's on a row.
4) Similarly he won't put more then "y" 1's on a row.
So our problem is simple. Given values of n , x and y, determine the total number
of unique points.
For example a valid plot for n = 9 , x = 2 , y =2 is :
Task :
Complete the function template dsp(). Which takes 3 inputs n,x and y.
Constraints :
Subproblem 1: (10 % marks )
1<= n <= 10
0 <= x <= 10
0 <= y <= 10
Subproblem 2: (20 % marks )
1<= n <= 100
0 <= x <= 10
0 <= y <= 10
Subproblem 3: (30 % marks )
1<= n <= 1000
0 <= x <= 10
0 <= y <= 10
Subproblem 4 : (40 % marks )
1<= n <= 1000
0 <= x <= 100
0 <= y <= 100
If the number gets very large Mr. Motlob will flee in terror, so in that case to calm
him down please output the modulo of result by 10^9 + 7
Sample Input and Output:
Input
n=4
x=2
y=2
Output = 6
Output = [ 1 , 3 ]
Special Note : Those who read "meme" as not , will not be graded :p
1) Since in a class of n students Mr. Motlob is the last student and his friend is the
first student, there sits (n-2) students between them. His friend will pass the answer
to him via the intermediate students.
2) His friend is very loyal and he will always say the right answer to the next
student.
3) However the other students are kind of strange, they may pass the correct
answer or may pass the wrong answer :/ We can estimate the probability that the i
th student will pass the correct answer as pi
4) Finally Mr. Motlob will always believe what the next student says and so he will
answer that exactly.
Now after the exam, due to his strange classmates Mr. Motlob would like to know
his expected score.
Task :
Complete the function template testScore(). Which takes 4 inputs n - the number of
students , m the number of questions , a vector p of size n-2 , indicating the
probabilty that the (i+1) th student will tell the correct answer [ here nth student is
Mr. Motlob and 1st student is his friend ] , next another vector of length m gives us
the actual answers ( 0 for false and 1 for true )
Subproblem 1 : (10 % marks )
2 <= n <= 5
1 <= m <= 5
Subproblem 2 : (20 % marks )
2 <= n <= 1000
1 <= m <= 5
Subproblem 3 : (30 % marks )
2 <= n <= 100000
1 <= m <= 5
Subproblem 4 : (40 % marks )
2 <= n <= 100000
1 <= m <= 10000
Sample Input and Output:
Input 1 :
n=3
m=1
p = [ 0.5]
answer = [ 1 ]
Output 1 = 0.5
Input 2 :
n=3
m=2
p = [ 0.5]
answer = [ 1 , 1 ]
Output 2 = 1.0
Note : Relative error up to 10-6 will be ignored.
Input 2 :
n= 3
m = 15
p = [ 10 10 10 ]
h=[135]
Output 2 = 5
You can't issue a book if it isn't already returned right ? So it is guaranteed that a
book will be returned before it is issued again .
Now after the month ends you go through the database record to see whether any
book hasn't been returned. From your experience you know that all the students
return their book, but a certain Mr. Motlob.
So if a book is missing you know for sure that it is the work of Mr. Motlob.
However like Schrodinger's Cat Mr. Motlob's behavior is also uncertain and
sometimes he returns his book as shocking it may be.
Now your job is to determine whether any book is missing or not.
INPUT :
Complete the function library() that takes 2 inputs ,N -> the number of database
entries of the month.
A vector d -> contains N positive integers di (1< i <N) the database entries (i.e.
book id) .
OUTPUT :
If any book is missing return it's id.
If no book is missing simply return "0"
It is granted that all but Mr. Motlob are law abiding students and they'll return their
book on time. So no more than one book can be missing .
Subproblems :
Subproblem 1 : (10 % marks)
N = 10
1 < di < 10 (only 10 books in library )
Subproblem 2 : (20 % marks)
N = 1000
1 < di < 1000 (only 1000 books in library )
Subproblem 3 : (30 % marks)
N = 100000
1 < di < 100000 (only 100000 books in library )
Subproblem 4 : ( 40 % marks )
N = 100000
1 < di < 1018 (1018 books in library )
Sample Input and Output:
Input 1 :
N=5
d=[1,2,3,2,1]
Output 1 = 3
Input 2 :
N=6
d = [ 1 , 2 ,3 , 3 , 2 , 1 ]
Output 2 = 0
Problem F : Product
( Just to let you this problem is nothing about Industrial Production dont worry)
Mr. Motlob was one day bragging that he can do multiplication very fast and
accurate. So his friends challenged him to do the following.
1) Mr. Motlob will be given an array of integers.
2) At any stage he will have to multiply a segment of the array.
3) The product may be very large. In such cases his friends thinks Mr. Motlob
is bluffing so they ask him to say the most significant digit of the entire
product.
Task :
Complete the function template Product (). Which takes 4 inputs n - the number of
elements in the array , m number of queries , a vector array of size n indicating
the i th element of array and a matrix query of size (m,2) denoting the (l,r) values
of each query.
Return a vector containing the first digit of product of each segments.
From this figure you get the idea, ideally in buet the internet is of quality 1 , at a
distance 5 there was a phone and so the quality became 100 e-0.5 (anything can
happen in this world right ?) Next at a distance of 5 no other phones were placed.
Next at home he placed another phone where the internet quality is
100 e-0.5 * 100 e-1 .
Now he want to know how to position the phones optimally so that he may get the
maximum internet quality. He doesnt bother about the positioning all he cares is
about the internet quality at home.
Task :
Complete the buetWifi() function that takes 5 inputs n number of possible safe
places , m number of phones Mr. Motlob bought , Dist the vector representing the
distance of ith safe spot from buet ,a and b the two constants mentioned above.
Output the best quality internet he may get at his home.
Constraints :
Subproblem 1 : (10 % marks)
1 <= n <= 5
m=1
1 <= Dist element <= 10
a is a real number
b is a real number
Subproblem 2 : (20 % marks)
1 <= n <= 5
1 <= m <= 5
1 <= Dist element <= 10
a is a real number
b is a real number
Subproblem 3 : (30 % marks)
1 <= n <= 1000
1 <= m <= 100
1 <= Dist element <= 10
a is a real number
b is a real number
Subproblem 4 : (40 % marks)
1 <= N <= 100000
1 <= M <= 100000
1 <= Dist element <= 10
a is a real number
b is a real number
Sample Input and Output:
Input 1 :
N=3
M=3
Dist = [5,10,15 ]
a = 100
b = 0.1
Output 1: 2.231301601484299e+05
Input 2 :
N=3
M=2
Dist = [5,10,15 ]
a = 0.1
b=-1
Output 2: 3.059023205018258e-08
Note : Relative Error less than 10-6 will be ignored.
Task :
Complete the pakhi() function. It takes 5 inputs B -> The amount of damage the
bullet can take , X - > x coordinate of Mr. Motlob , Y -> y coordinate of Mr.
Motlob , N number of birds and a Matrix Birds of size (N*3) -> x position , y
position and damage ith bird can inflict.
Constraints :
Subproblem 1 : (10 % marks)
1 <= N <= 10
1 <= B <= 1018
1 <= damage inflicted <= 1018
- 1000 <= coordinates <= 1000
Subproblem 2 : (20 % marks)
1 <= N <= 100
1 <= B <= 1018
1 <= damage inflicted <= 1018
- 1000 <= coordinates <= 1000
Subproblem 3 : (30 % marks)
1 <= N <= 1000
1 <= B <= 1018
1 <= damage inflicted <= 1018
- 1000 <= coordinates <= 1000
Subproblem 4 : (40 % marks)
1 <= N <= 100000
1 <= B <= 1018
1 <= damage inflicted <= 1018
- 1000 <= coordinates <= 1000
Sample Input and Output :
Input 1 : B=5
X=0
Y=0
N=4
Birds = [ 1 , 1 , 1
2 , 2 , 1
3 , 3 , 1
4 ,5 ,1 ]
Output = 3
Input 2 : B=5
X=0
Y=0
N=4
Birds = [ 1 , 1 , 10
2 , 2 , 1
3 , 3 , 1
4 , 5 , 1 ]
Output = 1
Problem J : Hacchoo
Due to season changing a lot of the students of Mr. Motlobs class is infected with
seasonal flue. Whats even worse is that they infect others by it too. In this classes
all the students sit side by side in row (quite a long bench it is! ) Initially maybe 3
or 4 or maybe more students are infected. After each second they say the magical
word Hacchoo and it will infect the two persons sitting next to them ( i.e. the
left one and the right one) . If they were previously infected it will have no affect
but otherwise they will be infected now.
When all the students of the class gets infected the class teacher dismisses the
class. Mr. Motlob wants to know when the class will be dismissed.
Task :
Complete the function hacchoo() it takes 2 inputs N-> Number of students , Class
-> a vector of size N which shows the initial condition if the ith student is infected
then the ith vector entry is 1 otherwise it 0.
Compute the time when the class will dismiss.
Constraints :
Subproblem 1 : (10 % marks)
1 <= n <= 10
Subproblem 2 : (20 % marks)
1 <= n <= 100
Subproblem 3 : (30 % marks)
1 <= n <= 1000
Subproblem 4 : (40 % marks)
1 <= N <= 100000
Sample Input and Output:
Input:
N=6
Class = [ 1 , 0 , 0 , 0 , 1 , 0 ]
Output = 2
Explanation :
Time = 0 -> Class = [ 1 , 0 , 0 , 0 , 1 , 0 ]
Time = 1 -> Class = [ 1 , 1 , 0 , 1 , 1 , 1 ]
Time = 2 -> Class = [ 1 , 1 , 1 , 1 , 1 , 1 ]
Problem K : No Name
For this problem Mr. Motlob wont tell you anything ( which you may already
realize from the problem name).
One day you say Mr. Motlob running a code and getting the following output.
Input -> Output
0 -> 0
1 -> 1
2 -> 1
3 -> 2
4 -> 1
5 -> 2
6 -> 2
7 -> 3
8 -> 1
9 -> 2
10 -> 2
11 -> 3
12 -> 2
13 -> 3
14 -> 3
15 -> 4
Task :
You have to complete the function noName() that takes only one input in and
return the corresponding output , as Mr. Motlob would generate from his code.
Constraints :
Subproblem 1 : (20 % marks)
1 <= in <= 15
Subproblem 2 : (80 % marks)
1<= in <= 1018
Sample Input and Output:
Input = 27
Output = 4
Problem L: Mr. Motlob and Friends
One day Mr. Motlob went to eat with 2 of his friends. Luckily you were one of
them, and the other one is so embarrassed right now he dont want to reveal his
name, so we will call him Fred.
Now as always Mr. Motlob forgot to bring his wallet. So it was decided that you
and Fred would pay for him. Note here that you and fred may both pay his money
or only one of you may pay his money.
Now Mr. Motlob gets pretty scared when it comes to counting big numbers. So to
keep him calm you and Fred told him a smaller normalized version of the payment.
For example if you paid 500 and Fred paid 400 you may represent that by 5 and 4
(or even 50 and 40). These small values make Mr. Motlob confident.
Now Mr. Motlob paid the remaining 300. It is obvious that you would receive 200
and Fred would receive 100. But Mr. Motlob thinks that you should get ( 5 / ( 5 + 4
) ) * 300 = 167.67 and Fred should receive (4/(5+4))*300 = 133.33.
But this calculation is wrong ( and also youre getting less than you should ) so you
complained Mr. Motlob. But unfortunately how much you try to make sense to
him, he doesnt believe you.
However Mr. Motlob says that he will only believe a computer, so your only hope
is that if you can manage write a code that would output the correct amount you
should receive.
Task :
complete friends() function which takes 3 inputs . A -> ratio of your payment , B -
> ratio of Freds payment , C -> The total money Mr. Motlob will return.
Output the correct amount of money you should receive.
Relative error upto 10-6 will be ignored.
Constraints :
Subproblem 1 : ( 10 % marks)
1 <= A <= 10
1 <= B <= 10
1 <= C <= 10
Subproblem 2 : ( 20 % marks)
1 <= A <= 100
1 <= B <= 100
1 <= C <= 100
Subproblem 3 : ( 30 % marks)
1 <= A <= 1000
1 <= B <= 1000
1 <= C <= 1000
Subproblem 4 : ( 40 % marks)
1 <= A <= 100000
1 <= B <= 100000
1 <= C <= 100000
Sample Input and Output :
Input 1 : A = 5
B=4
C = 300
Ouput 1 = 200
Input 2 : A = 6
B=3
C = 300
Ouput 2 = 300
Problem M: Gravity
Sometimes the philosopher inside Mr. Motlob arises. He was thinking about
gravity one day. Due to gravity a ball will roll down from an inclined surface,
unless it gets stuck somewhere.
Mr. Motlob believes from his philosophical insight that the ball of fig A and fig B
will drop down but for the case of fig C it will not.
So given the heights of the different segments of a surface can you determine
whether the ball would drop down or not ?
Task :
Complete the gravity() function that takes 2 input. N -> number of heights , Height
-> A vector of size N denoting the heights at different places.
If the ball falls down return 1 as output else return 0 as output.
Constraints :
Subproblem 1 : ( 10 % marks)
2 <= N <= 10
0 <= heights element <= 10000
Subproblem 2 : ( 20 % marks)
2 <= N <= 10
0 <= heights element <= 10000
Subproblem 3 : ( 30 % marks)
2 <= N <= 10
0 <= heights element <= 10000
Subproblem 4 : ( 40 % marks)
2 <= N <= 10
0 <= heights element <= 10000
Sample Input and Output:
Input 1 : N = 3
Height = [ 5 ,3 , 1 ]
Ouput 1 = 1
Input 2 : N = 3
Height = [ 5 ,3 , 5 ]
Ouput 2 = 0
Problem N: Not Every Hero Wears Cape
Mr. Motlob always wanted to be a hero. But he does not know how to fly like
Superman or he does not possess money, devices or the throat cancer(!!!!) like
Batman :P In the morning of his 18th birthday, he brought out a weighing machine
and found out his weight was over 50kg. So he decided to donate blood and turned
into a real life hero (kudos to this superhero). Our protagonist donates blood after
every 120 days. He does not waste a single day. He knows just 10minutes of his
life can add some years to another persons life.
You will be given the date of the18th birthday of this superhero and another date.
You have to tell how many times he has donated blood.
Task:
Input 1:
birthday=[ 1 1 2017]
today=[10 5 2017 ]
Output 1 : 2
Input 2:
birthday=[ 1 1 2017]
today=[1 1 2018 ]
Output 2: 4
Problem O :DX Ball
Mr. Motlob loves gaming. He started playing dx ball. But our beloved protagonist
missed the ball every single time and became fed up with the game. He decided to
create his own version of dx ball. There are blocks which are destroyed by the ball.
The ball is reflected diagonally every time it hits the ball or the wall of the matrix.
And guess what? There is no chance of being eliminated as there is no way to fall
down through the bottom of the matrix. Rather it is reflected just like the walls or
blocks whenever it hits the bottom. Mr. Motlob just starts the game by moving the
ball to a certain point of the matrix. From there the ball starts to move diagonally
and just goes on and on and on. A small part of the matrix is given below to get
familiarize with the co-ordinate system.
He was very much satisfied with it. But as soon as he started playing the game, he
found out that he cannot hit some blocks at all. He started looking for the bug in
the game but instead he found a bed bug in his hostels bed :3
Task:
Complete the function template cannot_hit=dxball(n,positon,start). Here n is the
number of blocks, position is a n*2 matrix where every row indicates the position
of the blocks and start is the co-ordinate from where the ball starts. You have to
return the number of balls which can never be hit in the cannot_hit variable.
Subproblem 1 : ( 10 % marks )
1 <= n <= 5
Subproblem 2 : ( 20 % marks )
1<= n <= 1000
Subproblem 3 : ( 30 % marks )
1 <= n <= 10000
Subproblem 4 : ( 40 % marks )
1 <= n <= 100000
Sample Input and Output :
Input 1 :
n=3
position=[ 1 2; 3 4; 2 6]
start=[ 1 1]
Output 1: 1
Input 2 :
n=5
position=[ 1 2; 3 4; 2 6; 4 5; 1001, 10001]
start=[ 2017 2020]
Output 2: 3
Problem P : Counting Stars
Mr. Motlob loves to gaze at the sky at night when no one is around him. He forgets
everything while doing so. He loves to create various shapes with the stars. His
most favorite shape is the circle. This thoughtful guy finds the stars which are on
the same circle. Then he starts from a star and imagines a straight line with the
adjacent star of the circle. He continues to do so until he returns to the first star.
Then with his amazing brain and imagination, he measures the total angle of the
shape he has just created by joining the stars.
Task:
Complete the function template m=stars(n). Here n is the number of stars on the
same circle. You have to return m. Here m=total angle of the shape/180 degree.
Sample Input: n=4
Output: 2
Problem Q : Back Calculation
Mr. Motlob one day who knows how generated a plot. He loved that very much so
he took a screenshot of it:
A zoomed in view
An even zoomed in view:
Now he would like very much to determine the function that generates this graph.
Please help him.
Task :
Complete the approximate() function . Which will take x as input and return value
of function at point x.
Note : This is an approximation problem. We don't expect you to give the correct
answer. You'll be graded relatively how better you've done compared to others.
The error will be computed as = abs (your output real value) / real value .
Sample input and Output :
Input:
x = 0.05
Output = 106.8