Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- public class MyClass {
- public static void main(String args[]) {
- new MyClass();
- }
- public class Chef{
- int x;
- int y;
- int val;
- }
- int n;
- Scanner sc;
- ArrayList<Chef> chefs = new ArrayList();
- public MyClass(){
- sc = new Scanner(System.in);
- n = sc.nextInt();
- chefs = getChefs();
- process();
- }
- void process(){
- int minDistance = Integer.MAX_VALUE;
- int x=0;
- int y=0;
- for(int i=0;i<n;i++){
- for(int j=0;j<n;j++){
- int totalDist = getTotalDist(j,i);
- if(minDistance>totalDist){
- minDistance = totalDist;
- x=j;
- y=i;
- }
- }
- }
- System.out.print(y+" "+x);
- }
- int getTotalDist(int x,int y){
- int sum = 0;
- for(int i=0;i<chefs.size();i++){
- sum+=Math.sqrt(Math.pow(chefs.get(i).x-x,2)+Math.pow(chefs.get(i).y-y,2));
- }
- return sum;
- }
- ArrayList<Chef> getChefs(){
- ArrayList<Chef> chefs = new ArrayList();
- for(int i=0;i<n;i++){
- for(int j=0;j<n;j++){
- int num = sc.nextInt();
- if(num>0){
- Chef chef = new Chef();
- chef.x=j;
- chef.y=i;
- chef.val=num;
- chefs.add(chef);
- }
- }
- }
- return chefs;
- }
- }
- /*
- 4
- -1 -1 -1 1
- -1 -1 -1 -1
- 2 -1 -1 -1
- 1 2 -1 -1
- */
Add Comment
Please, Sign In to add comment