Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Three friends set out to explore a remote area. They choose a safe place and make it their
Base Camp. To speed up exploration time they decide to work independently. At any given
point, either one or more of them can set out to explore the area. They set a protocol that
after exploring the area they must meet back at the Base Camp in the evening and
exchange notes.
The remote area consists of accessible and inaccessible pieces of land. Being ordinary
humans, they must walk only the accessible piece of land. In order to maximize their
exploration time, each one is interested in knowing about a shortest path back to the base
camp.
Given that the area under exploration is arranged in form of a rectangular grid, help the
explorers to chalk out a shortest path back to the base camp. Properties of a rectangle can
be used as heuristic in computing distance between their positions and the Base Camp.
Your task is to find out and mark the shortest path for each explorer and print each path
as a separate grid.
The input and output specification sections describe how inputs will be provided on
console and how output is expected back on console.
Input Format:
1. First line of input contains grid dimensions delimited by space character
2. Next rows number of lines contain column number of characters
3. Valid characters are {s, d, w, -}, where
Output Format:
1. Number of grids in the output should be same as number of explorers i.e. 's'
characters in the input grid
2. Each output grid should be of the same dimension as the input grid
3. Each output grid should contain path from explorer location s to base camp
location d
4. If there are more than one explorers, explorer with smallest value should be
printed first in the output. Next smallest explorer location should be printed next
followed by the last explorer grid.
5. First explorer path should be marked by 'a' character, second by 'b'
character and third by 'c' character
6. The 's' character in the grid must be replaced by {a, b or c} whichever is
appropriate for the given explorer
7. The 's' character(s) in the grid must be replaced by '-' character for other
explorer(s)
8. Output grids must be separated by a blank line
9. See example section for better understanding
Constraints:
1. It is guaranteed that there will always be exactly one shortest path for one explorer
from a given location
w-d-
waw-
44
waww
w-d-
a---
1 w-w-
w-ww
w-d-
s--s
wbw-
-1
wbww
--bb
a---
-a--
--a-
---d
44
s--s ---b
2 ---- ---b
---- ---b
s--d ---d
-1
----
----
----
cccd
Figure 2.
Note: - The output format shown above is for understanding purpose such that it
highlights the shortest path between the explorer and the base camp. The examples in
above table depicts output in text format as you will be required to provide.
Note:
Please do not use package and namespace in your code. For object oriented languages
your code should be written in one class.
Note:
Participants submitting solutions in C language should not use functions from / as these
files do not exist in gcc
Note:
Description of game:
2. Since two players are playing the game, they will make their moves
alternatively.
a. A player will choose a number from the table and will replace that
number with one of its divisor. For example, 6 can be replaced with 1, 2, or
3 (since these are the divisors of 6). Similarly, 12 can be replaced with 1, 2,
3, 4 or 6.
d. As 1 does not have any divisor other than itself, a player cannot
replace 1 with any other number. So soon a situation will arise when there
will be only all 1s on the table. In that situation the player will not be able to
make any move. The player who will not be able to make the move, loses.
4. Both the players are masters of this game. So they will play the game
optimally.
You will be given N integers that are on the table. You have to predict, who will win the
First line contains information about the numbers present of the table, denoted by N
Second line contains N integers delimited by space - A1 A2 A3 A4 ......... AN
Output Format:
Print the name of the player who will win the game in upper case i.e. AMAN or JASBIR.
Constraints:
1 <= N <= 100000
0 < Ai <= 10000
A player cannot replace more than 1 number in one move.
Players move alternate and a player cannot pass or make no move.
A number cannot be replaced itself, i.e. 6 can be replaced with 1, 2 or 3 only , not with 6.
Aman always makes the first move.
1 1
AMAN
6
2 2
AMAN
18 6
3 4
JASBIR
24 45 45 24
Explanation for sample input output 1:
There is only one number placed on the table do AMAN will replace it with 1. Jasbir will
play next. As there is only 1 left on the table. And it cannot be replaced with any other
number; he is not able to make any move. So he loses the game.
Explanation for sample input output 2:
There are 2 numbers present on the table. Since every move is the optimal move, Aman
will replace 18 with 6. Now (6, 6) will be left on the table. Now, whatever move Jasbir will
make. Aman will also make the same move. So whenever Jasbir will replace any number
with 1. In the next move Aman will also replace the other number with 1. So both the
numbers will be one after Aman's move. So Jasbir will lose the game.
Now, Jasbir WILL NOT BE ABLE TO MAKE ANY MOVE. So, Amanwill WIN.
Explanation for sample input output 3:
In this case, game is already symmetric. Aman has to make the first move. So whatever
move Aman will make Jasbir will just repeat the same. So In the Aman will go out of moves
and Jasbir will win the game.
Now, Aman WILL NOT BE ABLE TO MAKE ANY MOVE. So, Jasbir will WIN. It is easy to see
that just by mimicking Aman's moves, Jasbir will win.
Note:
Please do not use package and namespace in your code. For object oriented languages
Note:
Participants submitting solutions in C language should not use functions from / as these
Sheldon Cooper, Leonard Hofstadter and Penny decide to go for drinks at Cheese cake
factory. Sheldon proposes to make a game out of this. Sheldon proposes as follows,
To decide the amount of beverage they plan to consume, say X.
Then order for a random number of different drinks, say {A, B, C, D, E, F} of
quantities {a, b, c, d, e, f} respectively.
If quantity of any three drinks add up to X then we'll have it else we'll return the
order.
E.g. If a + d + f = X then True else False
sizes
beverage
Your task is to help find out if there can be any combination of three beverage sizes that
can sum up to the quantity they intend to consume. If such a combination is possible print
Input Format:
2. Next N lines, contains a positive integer A i, the size of the ith bottle
3. Last line contains the quantity they intend to consume denoted by X in text
above
Output Format:
True, if combination is possible
False, if combination is not possible
Constraints:
N >= 3
Ai > 0
1 <= i <= N
X>0
1 45
True
6
10
22
2
4 False
1
12
14
The sum of 2nd, 5th and 6th beverage size is equal to 22. So the output will be True.
Explanation for sample input and output 2:
Since no combination of given beverage sizes sum up to X i.e. 14, the output will be False.
Note:
Please do not use package and namespace in your code. For object oriented languages
Note:
Participants submitting solutions in C language should not use functions from / as these
Note:
By nature, an average Indian believes in saving money. Some reports suggest that an
average Indian manages to save approximately 30+% of his salary. Dhaniram is one such
hard working fellow. With a view of future expenses, Dhaniram resolves to save a certain
Dhaniram wants to buy a TV. He needs to pay Rs 2000/- per month for 12 installments to
own the TV. If let's say he gets 4% interest per annum on his savings bank account, then
Dhaniram will need to deposit a certain amount in the bank today, such that he is able to
withdraw Rs 2000/- per month for the next 12 months without requiring any additional
deposits throughout.
Your task is to find out how much Dhaniram should deposit today so that he gets assured
cash flows for a fixed period in the future, given the rate of interest at which his money
Input Format:
Third line contains rate per annum R expressed in percentage at which deposited amount
will grow
Output Format:
Print total amount of money to be deposited now rounded off to the nearest integer
Constraints:
M>0
T>0
R >= 0
Calculation should be done upto 11-digit precision
500
1
3 1470
12
6000
2
3 17824
5.9
500
3
2 1000
0
Note:
Please do not use package and namespace in your code. For object oriented languages
your code should be written in one class.
Note:
Participants submitting solutions in C language should not use functions from / as these
files do not exist in gcc
Note:
Catch 22
A robot is programmed to move forward F meters and backwards again, say B meters, in a
straight line. The Robot covers 1 meter in T units of time. On Robot's path there is a ditch
from initial position in backward direction. This forward and backward movement is
Input Format:
F B T FD BD, where
1. F denotes forward displacement in meters
2. B denotes backward displacement in meters
3. T denotes time taken to cover 1 meter
4. FD denotes distance from Robot's starting position and the ditch in forward
direction
5. BD denotes distance from Robot's starting position and the ditch in
backward direction
Output Format:
For each test case print time taken by the Robot to fall in the ditch and also state which
ditch he falls into. Print F for forward and B for backward. Both the outputs must be
delimited by whitespace
OR
Constraints:
3
63 F
1 9 4 3 13 10
25 F
9 7 1 11 13
No Ditch
4 4 3 8 12
5
133 F
8 4 7 11 22
216 B
2 4 5 4 25 6
231 B
4 9 3 6 29
408 B
7 10 6 24 12
9F
10 10 1 9 7
Note:
Please do not use package and namespace in your code. For object oriented languages
your code should be written in one class.
Note:
Participants submitting solutions in C language should not use functions from / as these
files do not exist in gcc
Note:
A futuristic company is building an autonomous car. The scientists at the company are
training the car to perform Reverse parking. To park, the car needs to be able to move in
backward as well as forward direction. The car is programmed to move backwards B meters
and forwards again, say F meters, in a straight line. The car does this repeatedly until it is
able to park or collides with other objects. The car covers 1 meter in T units of time. There is
a wall after distance D from car's initial position in the backward direction.
The car is currently not without defects and hence often hits the wall. The scientists are
devising a strategy to prevent this from happening. Your task is to help the scientists by
providing them with exact information on amount of time available before the car hits the
wall.
Input Format:
Output Format:
For each test case print time taken by the Car to hit the wall
Constraints:
First move will always be in backward direction
1 <= N <= 100
backward displacement > forward displacement i.e. (B > F)
forward displacement (F) > 0
backward displacement (B) > 0
time (T) > 0
distance (D) > 0
All input values must be positive integers only
2
1 162
6 9 3 18
220
3 7 5 20
Note:
Please do not use package and namespace in your code. For object oriented languages your
code should be written in one class.
Note:
Participants submitting solutions in C language should not use functions from / as these files
do not exist in gcc
Note:
Money Bank is an investment bank. It gives money to the companies for their operation that
approach it. The bank's officers have to calculate the maximum amount that the company
can be given, based on the company's market value and its market rating published by
Global Rating Companies. The maximum amount will change on a daily basis as per the
change in the company's shares, its market value and its change in rating. Based on the
maximum amount allocated, the bank internally calculates the amount that the company
can use on a particular day. The maximum amount that the bank will give at any point is
50% of the company's value, which will decrease as per the change in the company's rating.
Example:
Company ABC has 25734 shares in the market. The current value of the share is 77 INR. The
change in the Share Value from yesterday is +10(or 10) Today's rating of ABC is 87 (out of
100). The change in rating from yesterday is +2 (or 2). The credit and risk calculator will work
in the following way-
Similarly, company XYZ has 30000 shares in the market. The current value of the share is 90
INR. The change in the Share Value from yesterday is -15. Today's rating of XYZ is 83 (out of
100). The change in rating from yesterday is -4. The credit and risk calculator will work in the
following way-
PMax PCredit
Change Previous
Share PCompany Change Previous Credit Allotted
No. Of in Share Company
Valu Value (CV) in Rating Company is (CA)
Share Share Value Rating
e =N*min Rating (R')= Eligible for = CE *
s (N) Value (SV') = (R)
(SV) (SV, SV') ( CR) R-CR (CE) =CV * (min(R',
(CSV) SV-CSV
(50%) R)/100)
= (N*67) =
=
(CE*85/100)
1724178.00
= 25734 *
*0.5
25734 77 10 67.00 67 87 2 85.00 = 862089 *
0.85
=
=
862089.00
1724178.00 = 732775.65
OR
The Change in Share Value (CSV) and Change in Rating (CR) are dependent as below:
The values of CV, CE and CA are to be rounded to 2 Decimal Places, always to the Ceiling or
Upper Value
The range of the calculated values are-
20.00 <= SV' <= 10000.00
0.01 <= R' <= 99.99
All output values should be printed upto 2 decimal places.
4
25000
35
5
85
6
20000
30.00
19
79.00
2
750000.00
60
1 375000.00
3
296250.00
25658
Invalid Input
520
Invalid Input
510
Invalid Input
65
3
22000
30
-5
46
6
Note:
Please do not use package and namespace in your code. For object oriented languages your
code should be written in one class.
Note:
Participants submitting solutions in C language should not use functions from / as these files
do not exist in gcc
Note:
Ron Wesley has been bit by a three headed snake and Harry Potter is searching for a potion.
The Witch promises to tell the ingredients of the medicine if Harry can find equi pair of an
array. Listen to the conversation between Harry The witch to know more about equi pairs.
Conversation:-
The Witch : To find the equi pair, you must know how to find the slices first.
Harry : What is a slice?
The Witch : If Z is an array with N elements, a slice of indices (X, Y) is Z[X] + Z[X+1]...Z[Y]
Harry : How can I use it to find equi pair?
The Witch : (a, b) is an equi pair if slice of (0, a-1) = slice of (a+1, b-1) = slice of (b+1, N-1) and
b>a+1 and size of array > 4
Input Format:
OR
Print "Array does not contain any equi pair" if there are no equi pairs in the array
Constraints:
Zi >= 0 and 1<= i <=N
size of array (N) > 4
b > (a+1)
Sample Input and Output
Please do not use package and namespace in your code. For object oriented languages your
code should be written in one class.
Note:
Participants submitting solutions in C language should not use functions from / as these files
do not exist in gcc
Note:
In state of inebriation, a drunkard sets out to walk home, afoot. As is common knowledge, a
drunkard struggles to find balance and ends up taking random steps. Not surprisingly these
are steps in both forward as well as backward direction. Funnily enough, these are also
repeated movements. Now, it so happens that on this drunkard's path, there are two
banana skins - one in forward direction and one in backward direction. There is a real
danger that the drunkard's downfall may be accelerated if he accidentally slips over either
of those banana skins.
Your task is to find out if he will slip over the banana skin on forward path or banana skin on
backward path and in how much time. It is also possible that by his good fortune he might
not step over either banana skins. Write a program to calculate the outcome.
Input Format:
Output Format:
For each test case, print time taken by the Drunkard to slip over the forward or backward
banana skin. Print F if he slips over forward banana skin and B if he slips over the backward
banana skin. Both the outputs must be delimited by whitespace
OR
Print "Hurray" if the Drunkard is lucky to not slip over either banana skin
Constraints:
1 <= N <= 100
forward movement (FM) > 0
backward movement (BM) > 0
time (T) > 0
Distance to banana skin in forward direction (FBS) > 0
Distance to banana skin in backward direction (BBS) > 0
All input values must be integer only
6
28 B
B 14 12 7 25 4
156 F
B 11 4 6 10 17
1 675 B
F 2 3 9 12 15
102 B
F 1 12 3 22 28
Hurray
B 8 8 5 9 18
35 F
F88579
Note:
Please do not use package and namespace in your code. For object oriented languages your
code should be written in one class.
Note:
Participants submitting solutions in C language should not use functions from / as these files
do not exist in gcc
Note:
Two riders A and B are travelling on a highway towards each other on two roads that
intersect at right angle at speeds VAmeters/second and VB meters/second. A is at a distance
of 'x' meters and B is at a distance of 'y' meters from the intersection. Calculate the
minimum distance between these two riders that is possible.
Fig:Approaching Intersection
Input Format:
Print the minimum distance between these two riders, if minimum distance is non-zero. If
minimum distance is zero, print it as 0.0
Constraints:
x>0
y>0
VA > 0
VB > 0
Calculation and printing of output should be done upto 11-precision
100
1 100
0.0
10
10
500
2 300
41.18252056395
20
14
100
3 100
22.36067977500
30
40
0
5 50
Invalid Input
-20
30
Note:
Please do not use package and namespace in your code. For object oriented languages your
code should be written in one class.
Note:
Participants submitting solutions in C language should not use functions from / as these files
do not exist in gcc
Note:
Manisha is a smart investor. She has opened a Recurring Deposit (RD) account with a bank.
She has negotiated smartly with the bank. Bank has agreed to vary the interest rate on her
RD account such that she is always able to comfortably beat inflation.
Your task is to calculate maturity value of her RD account in face of varying interest rates
that she will enjoy.
Input Format:
Print the maturity amount after specified tenure or month in the format "Final_Amount "
Constraints:
P > 0 ; it can be float value
R >=0 ; it can be float value
T >0 ; it can be integer only
Calculation should be done upto 11-digit precision
Maturity amount should be printed to its nearest integer value
Sample Input and Output
5000
10
1 12
Final_Amount 63657
3 7 11
8 12 12
-1
2565.50
7.5
2
12 Final_Amount 32097
6 12 8
-1
200.75
3 6.9
Final_Amount 1021
5
-1
Note:
Please do not use package and namespace in your code. For object oriented languages your
code should be written in one class.
Note:
Participants submitting solutions in C language should not use functions from / as these files
do not exist in gcc
Note:
Due to the latest earthquake occurrences, the government of "Intelligent Country" is trying
to devise a mechanism which can accurately identify the danger zones based on the origin /
epicenter of the earthquake. The mechanism requires that the local map, the co-ordinates
of the epicenter and the intensity (measured in Richter scale) are provided as inputs to the
program. The output of the program would be the map marked with affected areas.
The local map is represented as a grid with square dimensions containing 0's and 1's only.
0's denote the areas which are water whereas 1 denotes the land areas. Based on the
epicenter co-ordinates, all the neighboring inhabited areas that would be affected needs to
be marked as '2'. This process will continue until all the neighboring land areas are
processed. Based on the intensity provided, the areas which would be most affected should
be marked as "high risk zones" denoted by '3'. The below table should be used for
reference.
Intensity Impact
<=3.0 All reachable land areas would be marked as affected areas.
The immediate neighbors to the epicenter are the high risk
>3.0 and <=5.0
zones.
The first three immediate neighbors would be marked as high
>5.0 and <=8.0
risk zones.
>8.0 All reachable land areas would be marked as high risk zones.
Table 1: Intensity-Impact Table
Input Format:
File name, where file contains the information in format described below:
1. First line contains an integer N which denotes the size of the grid
2. Next N lines each contain N elements delimited by space. These elements are
only 0's and 1's
3. Next line contains the coordinate of the epicenter. The following applies to
the Epicenter
Output Format:
The output or the resulting map (in the form of the square matrix) should be displayed
Sample Input and Output
1022
1 0003
Map1.txt
1030
0033
2
Map2.txt 033020202
000322220
333020022
333302000
030320000
300002222
333320222
002202222
102222002
1033
3 0003
Map3.txt
1003
0033
1022
4 0002
Map4.txt
1002
0022
Explanation:
To understand the input and the output, following content of the file are depicted along
with output for better understanding.
File
Contents of file Output Comments
Name
9 03302
011010101 0202 The intensity of quake is 6.95. Hence according to
000111110 00032 Intensity-Impact Table we have to consider three
111010011 2220 immediate neighbours. Three immediate neighbours
Map2.txt 1 1 1 1 0 1 0 0 0 33302 is a perimeter of 3 units from the epicenter. In this
010110000 0022 case the epicenter is (4,1). Hence the perimeter is
100001111 33330 from coordinates (1, 1) to (7, 4).Now applying, the
111110111 2000 rules we get the depicted output. Note that the
001101111 03032 epicenter is also marked as high risk zone.
101111001 0000
41 30000
6.95555930016315 2 2 2 2
33332
0222
00220
2222
10222
2002
4
1011
1033 The intensity of quake is 8.95. Hence according to
0001
Map3.txt 0003 Intensity-Impact Table we have to consider all
1001
1003 reachable land neighbours through which the quake
0011
0033 can propagate.
44
8.95
4
1011 The intensity of quake is 1.95. Hence according to
1022
0001 Intensity-Impact Table we have to consider all
Map4.txt 0002
1001 reachable land neighbours and mark them as
1002
0011 affected areas, denoted by 2. The epicenter is also
0022
13 marked as affected area.
1.95
Note:
Please do not use package and namespace in your code. For object oriented languages your
code should be written in one class.
Note:
Participants submitting solutions in C language should not use functions from / as these files
do not exist in gcc
Note: