Created
October 28, 2012 18:33
-
-
Save m00dy/3969383 to your computer and use it in GitHub Desktop.
interviewstreet meeting point problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it fails testcase 1 but others are fine..
i couldnt find where i sucked at