HAckerearth – HAWKEYE AND FLOODFILL ⇾⚄ (EASY)

code:

#include<bits/stdc++.h>
using namespace std;
int main()
{

int n;
int i,j;
long int p;
cin>>n>>i>>j>>p;
for(int m=0; m<n; m++)
{
	for(int k=0;k<n;k++)
	{
	   // printf("m=%d k=%d\n",m,k);
		long int u=m-i;
		long int y=k-j;
		//cout<<u<<" "<<y;
		if(u<0)
		{
			u=0-u;
		}
		if(y<0)
		{
			y=0-y;
		}
		long int max=0;
		if(u<y)
		{
			max=y;
		}
		else{
			max=u;
		}
		if(p-max>0)
		{
			printf("%ld ",p-max);
		}
		else{
			printf("0 ");
		}
	}
	printf("\n");
}
return 0;
}

another code:

#include<bits/stdc++.h>
#define pb push_back
using namespace std;
int main()
{
    vector<int> vec[1000];
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
        {
            vec[i].push_back(0);
            //printf("%d\n",i);
        }

    }
    int pow,x,y;
    cin>>x>>y>>pow;
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
        {
            if(pow-max(abs(x-i),abs(y-j))>0)
            {
                vec[i][j]=(pow-max(abs(x-i),abs(y-j)));
            }
            else
            {
                vec[i][j]=0;
            }
            cout<<vec[i][j]<<" ";
        }
        cout<<"\n";
    }

    return 0;
}

 

 

 

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published. Required fields are marked *