Computer Science, asked by teju5933, 1 year ago

In the Indian Ocean, there are several small islands. A war ship is stationed in the ocean and wants to find how many of these islands are within its striking power. For simplicity, the islands are all assumed to have square shapes and again, the curvature of the earth can be ignored. The coordinates of two opposite corners of the islands are given and the position of the ship is also given. You need to find the islands in the increasing sequence of their distances from the ship. The distance is the shortest distance – the distance of the nearest point on the island boundary from the ship. Use Manhattan Distance, i.e. distance between 2 points (x1,y1) and (x2,y2) is |x1-x2| + |y1-y2|.​

Answers

Answered by aparadhamanasa65
0

Answer:#include <stdio.h>

#include <stdlib.h>

int main()

{

int n,a[100][4],x,y,r[100][2],d1,d2,d3,d4,d;

int t,i,j;

scanf("%d",&n);

for(i=0;i<n;i++)

{scanf("%d%d%d%d",&a[i][0],&a[i][1],&a[i][2],&a[i][3]);

r[i][0]=i+1;

}

scanf("%d%d",&x,&y);

for(i=0;i<n;i++)

{ d1=abs(x-a[i][0])+abs(y-a[i][1]);

d2=abs(x-a[i][2])+abs(y-a[i][3]);

d3=abs(x-a[i][0])+abs(y-a[i][3]);

d4=abs(x-a[i][2])+abs(y-a[i][1]);

d=d1;

if(d>d2)

d=d2;

if(d>d3)

d=d3;

if(d>d4)

d=d4;

r[i][1]=d;

}

for(i=0;i<n;i++)

for(j=0;j<n-1;i++)

{

if(r[j][1]>r[j+1][1])

{

t=r[j][1];

r[j][1]=r[j+1][1];

r[j+1][1]=t;

t=r[j][0];

r[j][0]=r[j+1][0];

r[j+1][0]=t;

}

}

for(i=0;i<n;i++)

printf("%d\t",r[i][0]);

return 0;

}

Explanation:

Similar questions