Skip to content

Instantly share code, notes, and snippets.

@m00dy
Created October 28, 2012 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m00dy/3969383 to your computer and use it in GitHub Desktop.
Save m00dy/3969383 to your computer and use it in GitHub Desktop.
interviewstreet meeting point problem
import java.util.Scanner;
public class Solution {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
int N = scan.nextInt();
long[] x = new long[N];
long[] y = new long[N];
int pointnormal = 0;
double pointsdiff = 0.0f;
for(int i=0;i<N;i++)
{
x[i] = scan.nextLong();
y[i] = scan.nextLong();
}
long xnormal = 0L;
long ynormal = 0L;
for(int i=0;i<N;i++)
{
xnormal += x[i]/N;
ynormal += y[i]/N;
}
pointsdiff = Math.sqrt(Math.pow(xnormal-x[0], 2) + Math.pow(ynormal-y[0], 2));
for(int i=1;i<N;i++)
{
double tempdiff = Math.sqrt(Math.pow(xnormal-x[i], 2) + Math.pow(ynormal-y[i], 2));
if(pointsdiff > tempdiff)
{
pointsdiff = tempdiff;
pointnormal = i;
}
}
long sum = 0;
for(int i=0;i<N;i++)
{
if(i==pointnormal)
continue;
long sumx = Math.abs(x[i]-x[pointnormal]);
long sumy = Math.abs(y[i]-y[pointnormal]);
sum += Math.max(sumx, sumy);
}
System.out.println(sum);
}
}
@m00dy
Copy link
Author

m00dy commented Oct 28, 2012

it fails testcase 1 but others are fine..

i couldnt find where i sucked at

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment