Sei sulla pagina 1di 27

Problem : Base Camp

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

a. s represents the location of the explorer


b. d represents the location of the base camp
c. w represents inaccessible region
d. - represents accessible region
4. End of input is marked by -1 character

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

Sample Input and Output

SNo. Input Output

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

Explanation for sample input and output 1:


Figure 1.

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:

For C and C++, return type of main() function should be int.


Problem : Number Game
Aman and Jasbir are very intelligent guys of their batch. Today they are playing a game
"Game of Numbers".

Description of game:

1. There are N numbers placed on a table.

2. Since two players are playing the game, they will make their moves

alternatively.

3. In one move a player can perform the following operation.

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.

b. It is mandatory that the player has to replace the number.

c. A player cannot put back the same number on table.

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.

5. Aman will make the first move of the game.

You will be given N integers that are on the table. You have to predict, who will win the

game - Aman or Jasbir.


Input Format:

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.

Sample Input and Output

SNo. Input Output

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.

Initial configuration - (18, 6)


AFTER Aman's MOVE - (6, 6)
AFTER Jasbir's MOVE - (6, 3)
AFTER Aman's MOVE - (3, 3)
AFTER Jasbir's MOVE - (1, 3)
AFTER Aman's MOVE - (1, 1)

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.

Initial configuration - (24, 45, 45, 24)


AFTER Aman's MOVE - (1, 45, 45, 24)
AFTER Jasbir's MOVE - (1, 45, 45, 1)
AFTER Aman's MOVE - (1, 1, 45, 1)
AFTER Jasbir's MOVE - (1, 1, 1, 1)

Let's see if outcome changes if Aman replaces 24 by 6 instead of 1

Initial configuration - (24, 45, 45, 24)


AFTER Aman's MOVE - (6, 45, 45, 24)
AFTER Jasbir's MOVE - (6, 45, 45, 6)
AFTER Aman's MOVE - (6, 5, 45, 6)
AFTER Jasbir's MOVE - (6, 5, 5, 6)
AFTER Aman's MOVE - (3, 5, 5, 6)
AFTER Jasbir's MOVE - (3, 5, 5, 3)
AFTER Aman's MOVE - (1, 5, 5, 3)
AFTER Jasbir's MOVE - (1, 5, 5, 1)
AFTER Aman's MOVE - (1, 1, 5, 1)
AFTER Jasbir's MOVE - (1, 1, 1, 1)

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

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:

For C and C++, return type of main() function should be int.

Problem : Sheldon Cooper and his beverage paradigm

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

You are given

1. Number of bottles N corresponding to different beverages and hence their

sizes

2. Next N lines, contain a positive integer corresponding to the size of the

beverage

3. Last line consists of an integer value, denoted by X above

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

True else False

Input Format:

1. First line contains number of bottles ordered denoted by N

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

Sample Input and Output

SNo. Input Output

1 45
True
6

10

22

2
4 False
1

12

14

Explanation for sample input and output 1:

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

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:

For C and C++, return type of main() function should be int.

Problem : Saving for a rainy day

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

amount in order to meet his cash flow demands in the future.

Consider the following example.

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

will grow during this period.

Input Format:

First line contains desired cash flow M

Second line contains period in months denoted by T

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

Sample Input and Output

SNo. Input Output

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:

For C and C++, return type of main() function should be int.

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

at a distance FD from initial position in forward direction as well as a ditch at a distance BD

from initial position in backward direction. This forward and backward movement is

performed repeatedly by the Robot.


Your task is to calculate amount of time taken, before the Robot falls in either ditch, if at

all it falls in a ditch.

Input Format:

First line contains total number of test cases, denoted by N

Next N lines, contain a tuple containing 5 values delimited by space

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

Print No Ditch if the Robot does not fall in either ditch

Constraints:

1. First move will always be in forward direction


2. 1 <= N <= 100
3. forward displacement > 0
4. backward displacement > 0
5. time > 0
6. distance of ditch in forward direction (FD) > 0
7. distance of ditch in backward direction (BD) > 0
8. All input values must be positive integers only

Sample Input and Output

SNo. Input Output

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:

For C and C++, return type of main() function should be int.

Problem : Reverse Gear

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:

First line contains total number of test cases, denoted by N


Next N lines, contain a tuple containing 4 values delimited by space
F B T D, 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. D denotes distance from Car's starting position and the wall in backward
direction

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

Sample Input and Output

SNo. Input Output

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:

For C and C++, return type of main() function should be int.


Problem : Credit and Risk Calculator

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

30000 90 -15 105.00 2700000.0 83 -4 87 1350000.00 1120500.00

Input Format:(All black color headings are input in above table)

First line contains total number of test cases T


Each test case comprises of
 First line contains number of shares N
 Second line contains current share value SV
 Third line contains change in share value CSV
 Fourth line contains current rating R
 Fifth line contains change in rating CR

Output Format:(All blue color headings are output in above table)

In case of Valid inputs, print the following per line


Previous Share Value SV'
Previous Rating R'
Company Value CV
Maximum Credit CE
Credit Allotted CA

OR

Print "Invalid Input" in case of invalid input(s)


Constraints:
Highest Priority Constraint
 Share Value (SV and SV') can never be negative

Input related constraints:-


 1 <= T <=100
 20000 <= N <= 10000000
 20.00 <= SV <= 10000.00 (Note:- This is a numerical constraint only)
 -2000.00 <= CSV <= 2000.00 (Note:- This is a numerical constraint only)
 0.01 <= R <= 99.99 (Note:- This is a numerical constraint only)
 -10.00 <= CR <= 10.00 (Note:- This is a numerical constraint only)
 Calculation should be done upto 11-digit precision

The Change in Share Value (CSV) and Change in Rating (CR) are dependent as below:

1. If CSV is Positive, CR can be Positive or Negative.


2. If CSV is Negative, CR cannot be Positive.

Output related constraints:-

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.

The output will be invalid in the following cases-

The input ranges or conditions are not satisfied.


The ranges of calculated values are not satisfied.
The relation between CSV and CR is not satisfied

Sample Input and Output

Case # Input Output

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:

For C and C++, return type of main() function should be int.


Problem : Accico Equi Pairs

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:

An array of N integers delimited by white space


Output Format:

Print equi pair in first line in the format { a,b }


Print slices in the format { 0,a-1 }, { a+1,b-1 }, { b+1,N-1 }

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

SNo. Input Output

Indices which form equi pair {


1 8 3 5 2 10 6 7 9 5 2 3,6 }
Slices are { 0,2 },{ 4,5 },{ 7,9 }

Array does not contain any


2 62623319
equi pair

Explanation for sample input output 1:

Here index { 3,6 } is an equi pair.


Because Slice of { 0,2 } = 8+3+5=16 is equal to Slice of { 4,5 }=10+6 = 16 and it is equal to
Slice of { 7,9 }=9+5+2 =16
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:

For C and C++, return type of main() function should be int.

Problem : Drunkard's Walk

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:

First line contains total number of test cases, denoted by N


Next N lines, contain a tuple containing 6 values delimited by space
D FM BM T FBS BBS, where
1. D denotes direction, either F (Forward) or B (Backward)
2. FM denotes the magnitude of forward movement in meters
3. BM denotes the magnitude of backward movement in meters
4. T denotes time taken to cover 1 meter
5. FBS denotes distance from Drunkards' starting position and the banana skin
in forward direction
6. BBS denotes distance from Drunkards' starting position and the banana skin
in backward direction

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

Sample Input and Output

SNo. Input Output

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:

For C and C++, return type of main() function should be int.


Problem : Minimum Distance

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:

First line contains the distance of Rider A from intersection denoted by x


Second line contains the distance of Rider B from intersection denoted by y
Third line contains the Velocity of Rider A denoted by VA
Fourth line contains the Velocity of Rider B denoted by VB
Output 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

Sample Input and Output

SNo. Input Output

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:

For C and C++, return type of main() function should be int.

Problem : Recurring Deposit

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:

First line contains principle amount P


Second line contains original rate of interest per annum R
Third line contains tenure in months T
Next few lines contain a tuple with 3 values. Each tuple contains delimited by whitespace,
where updated _rate is applied on From_month and To_month, both inclusive.
-1 shows the end of input
Output 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

SNo. Input 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:

For C and C++, return type of main() function should be int.

Problem : Earthquake Damage Estimator

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

a. It always has to be a land area i.e. it has to be denoted by 1


b. Row and column indexes of the grid start with 1, not 0
c. Coordinates are delimited by space and are of format
4. Last line contains a float value, which denotes intensity of the earthquake in
Richter scale

Output Format:

The output or the resulting map (in the form of the square matrix) should be displayed
Sample Input and Output

SNo. Input 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

Note how epicenter (3, 3) is highlighted in 3rd row


4
and 3rd column.
1011
1022 The intensity of quake is 3.5. Hence according to
0001
Map1.txt 0003 Intensity-Impact Table we have to consider
1010
1030 immediate neighbours. The immediate land
0011
0033 neighbours are [(2,4) (4,3) and (4,4)]. Per rules, they
33
are set to high risk zone, denoted by 3. The epicenter
3.5
is also marked as high risk zone.

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:

For C and C++, return type of main() function should be int.

Potrebbero piacerti anche