Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C Code Skeleton Code: // CS1010 AY2015/6 Semester 2 PE2 Ex1 // // minefield.c // // Name: // Matriculation number: // plab-id: // Discussion group:
C Code
Skeleton Code:
// CS1010 AY2015/6 Semester 2 PE2 Ex1 // // minefield.c // // Name: // Matriculation number: // plab-id: // Discussion group: // Description: #include#define MAX_SIZE 10 int readField(int [][MAX_SIZE]); void printField(int [][MAX_SIZE], int); int main(void) { int field[MAX_SIZE][MAX_SIZE], aftermath[MAX_SIZE][MAX_SIZE]; int size; size = readField(field); printf("Aftermath: "); printField(aftermath, size); printf("Maximum damage: "); // Incomplete printf("Number of safe areas: "); // Incomplete return 0; } // Read in a minefield // Do NOT modify this function! int readField(int field[][MAX_SIZE]) { int i,j, size; printf("Enter size: "); scanf("%d", &size); printf("Enter minefield: "); for (i=0; i Test Cases: http://www.comp.nus.edu.sg/~cs1010/practice/2017s1/Practice-S09P08/testdata/
Exercise 1: Minefield Problem Statement During the World War Il period, anti-tank mines were used to damage or destroy vehicles including tanks and armored fighting vehicles. As a counter-move minesweepers were trained to deal with these mines. One (fictional) way of doing so is to first survey the areas in a minefield to classify the mines by power. A mine of power k, where k is a positive integer, deals damage to the area itself, as well as k-1 area(s) in four directions (i.e., north, south, east and west). For simplicity's sake, damage dealt diagonally or to areas outside the minefield is ignored For example, as shown in Fig. 1, a mine of power 1 only deals damage to the area itself (without affecting the neighbouring areas). In contrast, a mine of power 2 deals damage to the area itself and 1 neighbouring area in four directions. Figure 1. Areas of effect of mines of power 1, 2, and 3. After mapping out the mines in a zone, the minesweepers assess the aftermath (i.e., the number of mines each area will be hit by if all the mines are detonated). They also compute the maximum damage sustained and the number of safe areas. Based on this information, they then decide the best strategy to deal with the mines. For example, the minefield as shown below in Fig. 2a contains 4 mines: The two mines at [1]12 and[3][2 are of power 1, while the two at [2][1] and [2][3] are of power 2. minefield[0] | 0 | 0 | 0 | minefield 1] o minefield 2] 02 minefield 3) 0 0 1 0 0 minefield 4] 00 o o o Figure 2a. A aftermath[0] | 0 | 0 | 0 aftermath[1 0 1 1 1 0 aftermathl3) 0111 0 Figure 2b.The aftermath after all mines are detonated. minefield with 4 mines. The areas affected by these mines are as shown in the table below, while the aftermath after all the mines are detonated is as shown above in Fig. 2b Location PowerArea(s) affected [21[1], as well as [1][1], [2][0], [2][2] and [3][1] [2][3], as well as [11[3], [21[2], [21[4] and [3][3] [31[2] [21[3]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started