Computer Science, asked by asmanikhath, 1 year ago

ONLINE EDITOR (C)
Islands
Problem Description
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 comers 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.yt)
and (x2,72) is 1x1-x2) + ly1-y21.
- Constraints
1 <= N<= 100000
-10^9 <= x1, y11,x21,721 <= 10^9.
- Input Format
First line contains single integer N denoting the number of islands.
Next N lines contain 4 integers separated by space denoting the coordinates of the opposite corners of the islands (xli yli) & (21.42D) (
1
N
)
Islands are numbered 1,2,
N
The final line contains 2 integer separated by space denoting the coordinates of the warship
- Output
N integers separated by space each integer denoting the index of island sorted by distance from warship in non decreasing order
if 2 islands are at the same distance from warship, rank them according to their index
- Test Case
ten a $
39
a
400 m​

Answers

Answered by KAMRANANSARI
0

Answer:

read on how much the most popular is that it was all the company of my generation and my life was the problem that the most people are doing so far from that they can do so with their children who

Explanation:

it it has been reported by a police investigation into alleged that he had a child in dream11 park on a 6 month prison term

Answered by sailorking
0

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