Knowee
Questions
Features
Study Tools

Help the doctorSabarish, A doctor forms a grid where each cell represents the condition of a patient. The cell can take any of the three values as follows:              1-The person is virus free              2-The person is infected with the virus               3-Empty cellIt takes one day for the virus to spread from one person to another. Every day any virus free person who is adjacent (4-directionally) to the infected person catches the disease.Given the initial grid help the doctor to find the minimum number of days that must elapse until everyone has been infected. If this impossible return -1.Example:-Suppose the input grid is 2 1 1                                             1 1 3                                            3 1 1After day 1 the grid will be    2 2 1                                                  2 1 3                                                  3 1 1After day 2 the grid  will be  2 2 2                                                 2 2 3                                                 3 1 1 After day 3 the grid will be 2 2 2                                               2 2 3                                               3 2 1After day 4 the grid will be 2 2 2                                               2 2 3                                               3 2 2So, the minimum number of days is 4Input format:-Numbers of row in the gridNumbers of column in the gridContents of the grid(next row*column lines)Output format:-Minimum number of days required

Question

Help the doctorSabarish, A doctor forms a grid where each cell represents the condition of a patient. The cell can take any of the three values as follows:              1-The person is virus free              2-The person is infected with the virus               3-Empty cellIt takes one day for the virus to spread from one person to another. Every day any virus free person who is adjacent (4-directionally) to the infected person catches the disease.Given the initial grid help the doctor to find the minimum number of days that must elapse until everyone has been infected. If this impossible return -1.Example:-Suppose the input grid is 2 1 1                                             1 1 3                                            3 1 1After day 1 the grid will be    2 2 1                                                  2 1 3                                                  3 1 1After day 2 the grid  will be  2 2 2                                                 2 2 3                                                 3 1 1 After day 3 the grid will be 2 2 2                                               2 2 3                                               3 2 1After day 4 the grid will be 2 2 2                                               2 2 3                                               3 2 2So, the minimum number of days is 4Input format:-Numbers of row in the gridNumbers of column in the gridContents of the grid(next row*column lines)Output format:-Minimum number of days required

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

The problem you're describing is a classic Breadth-First Search (BFS) problem in graph theory. Here's a step-by-step solution:

  1. First, we need to identify the size of the grid, which is given by the number of rows and columns. We also need to identify the initial state of each cell in the grid.

  2. We start by identifying all the cells that are initially infected with the virus (value 2). These cells are our starting points for the BFS.

  3. We then perform a BFS from each of these starting points. In each step of the BFS, we look at all virus-free cells (value 1) that are adjacent to a cell that is currently infected. We then infect these cells and add them to our queue of cells to process.

  4. We keep track of the number of days that have passed, which is equivalent to the number of steps in our BFS.

  5. We continue this process until there are no more cells to infect. If we reach a point where there are still virus-free cells but no more cells to infect, we return -1 as it is impossible for everyone to be infected.

  6. If we manage to infect all cells, we return the number of days that have passed.

This algorithm ensures that we infect cells in

This problem has been solved

Similar Questions

Sabarish, A doctor forms a grid where each cell represents the condition of a patient. The cell can take any of the three values as follows:              1-The person is virus free              2-The person is infected with the virus               3-Empty cellIt takes one day for the virus to spread from one person to another. Every day any virus free person who is adjacent (4-directionally) to the infected person catches the disease.Given the initial grid help the doctor to find the minimum number of days that must elapse until everyone has been infected. If this impossible return -1.Example:-Suppose the input grid is 2 1 1                                             1 1 3                                            3 1 1After day 1 the grid will be    2 2 1                                                  2 1 3                                                  3 1 1After day 2 the grid  will be  2 2 2                                                 2 2 3                                                 3 1 1 After day 3 the grid will be 2 2 2                                               2 2 3                                               3 2 1After day 4 the grid will be 2 2 2                                               2 2 3                                               3 2 2So, the minimum number of days is 4Input format:-Numbers of row in the gridNumbers of column in the gridContents of the grid(next row*column lines)Output format:-Minimum number of days required

On a street, there are N individuals (numbered from 1 to N) positioned along the line. Each person's position is denoted by Xi.Here's the situation: among these people, one person is unknowingly carrying the COVID-19 virus. The virus spreads if the distance between an infected person and a healthy person is no more than 2 units. As time goes on, a certain group of individuals (depending on who the initial infected person is) will become infected. Let's refer to the size of this group as the final count of infected people.Your goal is to print the smallest and largest possible number of people who could end up infected. This means finding the minimum and maximum counts of infected individuals, considering both the most favorable and the least favorable scenarios for how the virus spreads among the people on the street.Input FormatThe first line of each test case contains a single integer N.The second line contains N space-separated integers X1, X2, ..., XN.Constraints2 ≤ N ≤ 80 ≤ Xi ≤ 10 for each valid i0 ≤ X1 < X2 < ... < XNOutput FormatPrint a single line containing two space-separated integers ― the minimum and maximum possible final number of infected people.Sample Input 021 2Sample Output 02 2Sample Input 123 6Sample Output 11 1

For an infection to occur, how many conditions must be present? Input the correct answer in numeric form into the space provided.

Given three integers, A, B and C. You have to find the number of days it will take to reach zero cases of Corona in a city.A - Average cases recovered in a day of the corona.B - Number of new cases of corona daily.C - Current active cases of the corona.Return the minimum number of days it will take to reach 0 active cases of Covid.Problem Constraints1 <= B < A <= 50001 <= C <= 1000Input FormatThe first argument will be integer A, which denotes the recovered cases in a day.The second argument will be integer B, which denotes the new cases in a day.The third argument will be integer C, which denotes the currently active cases.Output FormatReturn an integer which denotes the minimum days to reach 0 cases.Example InputInput 1:A = 5B = 3C = 1Input 2:A = 4B = 3C = 2

The spread of a disease can be modeled as , where N is the number of infected people, and t is time (in days).How long will it take until the number of infected people reaches 1,400?

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.