Posts

Search

Grid

QUESTION DESCRIPTION

Manisa is not having a good time these days. Just Yesterday he made terrible food and hence got beaten up. He has hence decided that he wont prepare food himself but instead collect food from hotels in the city.

However, he suffered injury on his head ( people can get really angry when served with bad food ) and is suffering from short term memory loss.

He is standing in a city in the form of a grid where cell(i,j) of the grid contains a hotel which has Gij amount of food to offer to the chef.

Every second, monisha goes to one of the neighbors in the grid. ( Note: Please note that any cell(i,j) can have at most 4 neighbors). Now the task is locate the files in index method to display.

TEST CASE 1

INPUT
2
3
4
9 
4 6  7
5
2
8
OUTPUT
1 3 4
2 5 2
blocks occupied are:
fileno1: 3 9 3 4 3 6 3 7
fileno2: 5 8 5 0

TEST CASE 2

INPUT
2
4
4
8 
5  7  8
6
2
8
OUTPUT
1 4 4
2 6 2
blocks occupied are:
fileno1: 4 8 4 5 4 7 4 8
fileno2: 6 8 6 0

Code :

#include <iostream>
using namespace std;
class emp{
public:
  int k;
  int n;
  int a[100];
};
int main() {
  int t;
  cin>>t;
  emp o[t];
  for(int i=0;i<t;i++)
  {
    cin>>o[i].k>>o[i].n;
   for(int j=0;j<o[i].n;j++)
     cin>>o[i].a[j];
  }
  for(int i=0;i<t;i++)
  {cout<<i+1<<" "<<o[i].k<<" "<<o[i].n<<endl;
  }
  cout<<"blocks occupied are:\n";
  for(int i=0;i<t;i++)
  {
    cout<<"fileno"<<i+1<<":";
    for(int j=0;j<o[i].n;j++)
    {cout<<" "<<o[i].k<<" "<<o[i].a[j];
    }
    cout<<endl;
  }
    
  return 0;
}