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.
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. |
>3.0 and <=5.0 | The immediate neighbors to the epicenter are the high risk zones. |
>5.0 and <=8.0 | The first three immediate neighbors would be marked as high risk zones. |
>8.0 | All reachable land areas would be marked as high risk zones. |
Input Format:
File name, where file contains the information in format described below:
File name, where file contains the information in format described below:
- First line contains an integer N which denotes the size of the grid
- Next N lines each contain N elements delimited by space. These elements are only 0's and 1's
- Next line contains the coordinate of the epicenter. The following applies to the Epicenter
- It always has to be a land area i.e. it has to be denoted by 1
- Row and column indexes of the grid start with 1, not 0
- Coordinates are delimited by space and are of format
- 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 OutputThe output or the resulting map (in the form of the square matrix) should be displayed
SNo. | Input | Output |
---|---|---|
1 | Map1.txt | 1 0 2 2 0 0 0 3 1 0 3 0 0 0 3 3 |
2 | Map2.txt | 0 3 3 0 2 0 2 0 2 0 0 0 3 2 2 2 2 0 3 3 3 0 2 0 0 2 2 3 3 3 3 0 2 0 0 0 0 3 0 3 2 0 0 0 0 3 0 0 0 0 2 2 2 2 3 3 3 3 2 0 2 2 2 0 0 2 2 0 2 2 2 2 1 0 2 2 2 2 0 0 2 |
3 | Map3.txt | 1 0 3 3 0 0 0 3 1 0 0 3 0 0 3 3 |
4 | Map4.txt | 1 0 2 2 0 0 0 2 1 0 0 2 0 0 2 2 |
Explanation:
To understand the input and the output, following content of the file are depicted along with output for better understanding.
To understand the input and the output, following content of the file are depicted along with output for better understanding.
File Name | Contents of file | Output | Comments |
---|---|---|---|
Map1.txt | 4 1 0 1 1 0 0 0 1 1 0 1 0 0 0 1 1 3 3 3.5 | 1 0 2 2 0 0 0 3 1 0 3 0 0 0 3 3 | Note how epicenter (3, 3) is highlighted in 3rd row and 3rd column. The intensity of quake is 3.5. Hence according to Intensity-Impact Table we have to consider immediate neighbours. The immediate land neighbours are [(2,4) (4,3) and (4,4)]. Per rules, they are set to high risk zone, denoted by 3. The epicenter is also marked as high risk zone. |
Map2.txt | 9 0 1 1 0 1 0 1 0 1 0 0 0 1 1 1 1 1 0 1 1 1 0 1 0 0 1 1 1 1 1 1 0 1 0 0 0 0 1 0 1 1 0 0 0 0 1 0 0 0 0 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 1 1 0 1 1 1 1 1 0 1 1 1 1 0 0 1 4 1 6.95555930016315 | 0 3 3 0 2 0 2 0 2 0 0 0 3 2 2 2 2 0 3 3 3 0 2 0 0 2 2 3 3 3 3 0 2 0 0 0 0 3 0 3 2 0 0 0 0 3 0 0 0 0 2 2 2 2 3 3 3 3 2 0 2 2 2 0 0 2 2 0 2 2 2 2 1 0 2 2 2 2 0 0 2 | The intensity of quake is 6.95. Hence according to Intensity-Impact Table we have to consider three immediate neighbours. Three immediate neighbours is a perimeter of 3 units from the epicenter. In this case the epicenter is (4,1). Hence the perimeter is from coordinates (1, 1) to (7, 4).Now applying, the rules we get the depicted output. Note that the epicenter is also marked as high risk zone. |
Map3.txt | 4 1 0 1 1 0 0 0 1 1 0 0 1 0 0 1 1 4 4 8.95 | 1 0 3 3 0 0 0 3 1 0 0 3 0 0 3 3 | The intensity of quake is 8.95. Hence according to Intensity-Impact Table we have to consider all reachable land neighbours through which the quake can propagate. |
Map4.txt | 4 1 0 1 1 0 0 0 1 1 0 0 1 0 0 1 1 1 3 1.95 | 1 0 2 2 0 0 0 2 1 0 0 2 0 0 2 2 | The intensity of quake is 1.95. Hence according to Intensity-Impact Table we have to consider all reachable land neighbours and mark them as affected areas, denoted by 2. The epicenter is also marked as affected area. |
Note:
Please do not use package and namespace in your code. For object oriented languages your code should be written in one class.
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
Participants submitting solutions in C language should not use functions from
Note:
For C and C++, return type of main() function should be int.
For C and C++, return type of main() function should be int.
No comments :
Post a Comment