Computer Science, asked by bhanu4480, 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 382006
3

Answer:

very very complicated question, I can't answer it! really.

Answered by sailorking
2

Answer:

import java.util.*;

Class pro

{

public static void main(String args[])

{

    int n,arr1[][],x,y,arr2[][],sh1,sh2,sh3,sh4,d;

arr1=new int[100][4];

arr2=new int[100][2];

 int t,i,j;

System.out.println(“Enter input”)

 n=sc.nextInt();

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

{

arr[i][0]= sc.nextInt();

arr1[i][1]= sc.nextInt();

arr1[i][2]= sc.nextInt();

arr1[i][3]= sc.nextInt();

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

 }

System.out.println(“Enter input for x”)

x=sc.nextInt();

System.out.println(“Enter input for y”)

y=sc.nextInt();

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

{

sh1=abs(x-arr1[i][0])+abs(y-arr1[i][1]);

sh2=abs(x-arr1[i][2])+abs(y-arr1[i][3]);

sh3=abs(x-arr1[i][0])+abs(y-arr1[i][3]);

sh4=abs(x-arr1[i][2])+abs(y-arr1[i][1]);

d=sh1;

if(d>sh2)

d=sh2;

if(d>sh3)

d=sh3;

if(d>sh4)

d=sh4;

arr2[i][1]=d;

}

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

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

{

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

{

t=arr2[j][1];

arr2[j][1]=arr2[j+1][1];

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

t=arr2[j][0];

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

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

}

}

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

System.out.println(“\t”+arr2[i][0]);

}

Similar questions